| 1 | /* | |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
| 3 | * contributor license agreements. See the NOTICE file distributed with | |
| 4 | * this work for additional information regarding copyright ownership. | |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
| 6 | * (the "License"); you may not use this file except in compliance with | |
| 7 | * the License. You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | package org.apache.commons.collections4; | |
| 18 | ||
| 19 | import java.io.PrintStream; | |
| 20 | import java.text.NumberFormat; | |
| 21 | import java.text.ParseException; | |
| 22 | import java.util.ArrayDeque; | |
| 23 | import java.util.Collection; | |
| 24 | import java.util.Collections; | |
| 25 | import java.util.Deque; | |
| 26 | import java.util.Enumeration; | |
| 27 | import java.util.HashMap; | |
| 28 | import java.util.Iterator; | |
| 29 | import java.util.Map; | |
| 30 | import java.util.Objects; | |
| 31 | import java.util.Map.Entry; | |
| 32 | import java.util.Properties; | |
| 33 | import java.util.ResourceBundle; | |
| 34 | import java.util.SortedMap; | |
| 35 | import java.util.TreeMap; | |
| 36 | import java.util.function.BiFunction; | |
| 37 | import java.util.function.Function; | |
| 38 | ||
| 39 | import org.apache.commons.collections4.map.AbstractMapDecorator; | |
| 40 | import org.apache.commons.collections4.map.AbstractSortedMapDecorator; | |
| 41 | import org.apache.commons.collections4.map.FixedSizeMap; | |
| 42 | import org.apache.commons.collections4.map.FixedSizeSortedMap; | |
| 43 | import org.apache.commons.collections4.map.LazyMap; | |
| 44 | import org.apache.commons.collections4.map.LazySortedMap; | |
| 45 | import org.apache.commons.collections4.map.ListOrderedMap; | |
| 46 | import org.apache.commons.collections4.map.MultiValueMap; | |
| 47 | import org.apache.commons.collections4.map.PredicatedMap; | |
| 48 | import org.apache.commons.collections4.map.PredicatedSortedMap; | |
| 49 | import org.apache.commons.collections4.map.TransformedMap; | |
| 50 | import org.apache.commons.collections4.map.TransformedSortedMap; | |
| 51 | import org.apache.commons.collections4.map.UnmodifiableMap; | |
| 52 | import org.apache.commons.collections4.map.UnmodifiableSortedMap; | |
| 53 | ||
| 54 | /** | |
| 55 | * Provides utility methods and decorators for {@link Map} and {@link SortedMap} instances. | |
| 56 | * <p> | |
| 57 | * It contains various type safe methods as well as other useful features like deep copying. | |
| 58 | * </p> | |
| 59 | * <p> | |
| 60 | * It also provides the following decorators: | |
| 61 | * </p> | |
| 62 | * | |
| 63 | * <ul> | |
| 64 | * <li>{@link #fixedSizeMap(Map)} | |
| 65 | * <li>{@link #fixedSizeSortedMap(SortedMap)} | |
| 66 | * <li>{@link #lazyMap(Map,Factory)} | |
| 67 | * <li>{@link #lazyMap(Map,Transformer)} | |
| 68 | * <li>{@link #lazySortedMap(SortedMap,Factory)} | |
| 69 | * <li>{@link #lazySortedMap(SortedMap,Transformer)} | |
| 70 | * <li>{@link #predicatedMap(Map,Predicate,Predicate)} | |
| 71 | * <li>{@link #predicatedSortedMap(SortedMap,Predicate,Predicate)} | |
| 72 | * <li>{@link #transformedMap(Map, Transformer, Transformer)} | |
| 73 | * <li>{@link #transformedSortedMap(SortedMap, Transformer, Transformer)} | |
| 74 | * <li>{@link #multiValueMap( Map )} | |
| 75 | * <li>{@link #multiValueMap( Map, Class )} | |
| 76 | * <li>{@link #multiValueMap( Map, Factory )} | |
| 77 | * </ul> | |
| 78 | * | |
| 79 | * @since 1.0 | |
| 80 | */ | |
| 81 | @SuppressWarnings("deprecation") | |
| 82 | public class MapUtils { | |
| 83 | ||
| 84 | /** | |
| 85 | * An empty unmodifiable sorted map. This is not provided in the JDK. | |
| 86 | */ | |
| 87 | @SuppressWarnings("rawtypes") | |
| 88 | public static final SortedMap EMPTY_SORTED_MAP = UnmodifiableSortedMap.unmodifiableSortedMap(new TreeMap<>()); | |
| 89 | ||
| 90 | /** | |
| 91 | * String used to indent the verbose and debug Map prints. | |
| 92 | */ | |
| 93 | private static final String INDENT_STRING = " "; | |
| 94 | ||
| 95 | /** | |
| 96 | * Applies the {@code getFunction} and returns its result if non-null, if null returns the result of applying the | |
| 97 | * default function. | |
| 98 | * | |
| 99 | * @param <K> The key type. | |
| 100 | * @param <R> The result type. | |
| 101 | * @param map The map to query. | |
| 102 | * @param key The key into the map. | |
| 103 | * @param getFunction The get function. | |
| 104 | * @param defaultFunction The function to provide a default value. | |
| 105 | * @return The result of applying a function. | |
| 106 | */ | |
| 107 | private static <K, R> R applyDefaultFunction(final Map<? super K, ?> map, final K key, | |
| 108 | final BiFunction<Map<? super K, ?>, K, R> getFunction, final Function<K, R> defaultFunction) { | |
| 109 |
1
1. applyDefaultFunction : replaced return value with null for org/apache/commons/collections4/MapUtils::applyDefaultFunction → KILLED |
return applyDefaultFunction(map, key, getFunction, defaultFunction, null); |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * Applies the {@code getFunction} and returns its result if non-null, if null returns the result of applying the | |
| 114 | * default function. | |
| 115 | * | |
| 116 | * @param <K> The key type. | |
| 117 | * @param <R> The result type. | |
| 118 | * @param map The map to query. | |
| 119 | * @param key The key into the map. | |
| 120 | * @param getFunction The get function. | |
| 121 | * @param defaultFunction The function to provide a default value. | |
| 122 | * @param defaultValue The default value. | |
| 123 | * @return The result of applying a function. | |
| 124 | */ | |
| 125 | private static <K, R> R applyDefaultFunction(final Map<? super K, ?> map, final K key, | |
| 126 | final BiFunction<Map<? super K, ?>, K, R> getFunction, final Function<K, R> defaultFunction, | |
| 127 | final R defaultValue) { | |
| 128 |
2
1. applyDefaultFunction : negated conditional → SURVIVED 2. applyDefaultFunction : negated conditional → SURVIVED |
R value = map != null && getFunction != null ? getFunction.apply(map, key) : null; |
| 129 |
1
1. applyDefaultFunction : negated conditional → KILLED |
if (value == null) { |
| 130 |
1
1. applyDefaultFunction : negated conditional → KILLED |
value = defaultFunction != null ? defaultFunction.apply(key) : null; |
| 131 | } | |
| 132 |
2
1. applyDefaultFunction : negated conditional → KILLED 2. applyDefaultFunction : replaced return value with null for org/apache/commons/collections4/MapUtils::applyDefaultFunction → KILLED |
return value != null ? value : defaultValue; |
| 133 | } | |
| 134 | ||
| 135 | /** | |
| 136 | * Applies the {@code getFunction} and returns its result if non-null, if null returns the {@code defaultValue}. | |
| 137 | * | |
| 138 | * @param <K> The key type. | |
| 139 | * @param <R> The result type. | |
| 140 | * @param map The map to query. | |
| 141 | * @param key The key into the map. | |
| 142 | * @param getFunction The get function. | |
| 143 | * @param defaultValue The default value. | |
| 144 | * @return The result of applying a function. | |
| 145 | */ | |
| 146 | private static <K, R> R applyDefaultValue(final Map<? super K, ?> map, final K key, | |
| 147 | final BiFunction<Map<? super K, ?>, K, R> getFunction, final R defaultValue) { | |
| 148 |
2
1. applyDefaultValue : negated conditional → KILLED 2. applyDefaultValue : negated conditional → KILLED |
final R value = map != null && getFunction != null ? getFunction.apply(map, key) : null; |
| 149 |
2
1. applyDefaultValue : negated conditional → KILLED 2. applyDefaultValue : replaced return value with null for org/apache/commons/collections4/MapUtils::applyDefaultValue → KILLED |
return value == null ? defaultValue : value; |
| 150 | } | |
| 151 | ||
| 152 | /** | |
| 153 | * Prints the given map with nice line breaks. | |
| 154 | * <p> | |
| 155 | * This method prints a nicely formatted String describing the Map. Each map entry will be printed with key, value | |
| 156 | * and value classname. When the value is a Map, recursive behaviour occurs. | |
| 157 | * </p> | |
| 158 | * <p> | |
| 159 | * This method is NOT thread-safe in any special way. You must manually synchronize on either this class or the | |
| 160 | * stream as required. | |
| 161 | * </p> | |
| 162 | * | |
| 163 | * @param out the stream to print to, must not be null | |
| 164 | * @param label The label to be used, may be {@code null}. If {@code null}, the label is not output. It | |
| 165 | * typically represents the name of the property in a bean or similar. | |
| 166 | * @param map The map to print, may be {@code null}. If {@code null}, the text 'null' is output. | |
| 167 | * @throws NullPointerException if the stream is {@code null} | |
| 168 | */ | |
| 169 | public static void debugPrint(final PrintStream out, final Object label, final Map<?, ?> map) { | |
| 170 |
1
1. debugPrint : removed call to org/apache/commons/collections4/MapUtils::verbosePrintInternal → KILLED |
verbosePrintInternal(out, label, map, new ArrayDeque<Map<?, ?>>(), true); |
| 171 | } | |
| 172 | ||
| 173 | /** | |
| 174 | * Returns an immutable empty map if the argument is {@code null}, or the argument itself otherwise. | |
| 175 | * | |
| 176 | * @param <K> the key type | |
| 177 | * @param <V> the value type | |
| 178 | * @param map the map, possibly {@code null} | |
| 179 | * @return an empty map if the argument is {@code null} | |
| 180 | */ | |
| 181 | public static <K, V> Map<K, V> emptyIfNull(final Map<K, V> map) { | |
| 182 |
2
1. emptyIfNull : negated conditional → KILLED 2. emptyIfNull : replaced return value with null for org/apache/commons/collections4/MapUtils::emptyIfNull → KILLED |
return map == null ? Collections.<K, V>emptyMap() : map; |
| 183 | } | |
| 184 | ||
| 185 | /** | |
| 186 | * Returns a fixed-sized map backed by the given map. Elements may not be added or removed from the returned map, | |
| 187 | * but existing elements can be changed (for instance, via the {@link Map#put(Object,Object)} method). | |
| 188 | * | |
| 189 | * @param <K> the key type | |
| 190 | * @param <V> the value type | |
| 191 | * @param map the map whose size to fix, must not be null | |
| 192 | * @return a fixed-size map backed by that map | |
| 193 | * @throws NullPointerException if the Map is null | |
| 194 | */ | |
| 195 | public static <K, V> IterableMap<K, V> fixedSizeMap(final Map<K, V> map) { | |
| 196 |
1
1. fixedSizeMap : replaced return value with null for org/apache/commons/collections4/MapUtils::fixedSizeMap → NO_COVERAGE |
return FixedSizeMap.fixedSizeMap(map); |
| 197 | } | |
| 198 | ||
| 199 | /** | |
| 200 | * Returns a fixed-sized sorted map backed by the given sorted map. Elements may not be added or removed from the | |
| 201 | * returned map, but existing elements can be changed (for instance, via the {@link Map#put(Object,Object)} method). | |
| 202 | * | |
| 203 | * @param <K> the key type | |
| 204 | * @param <V> the value type | |
| 205 | * @param map the map whose size to fix, must not be null | |
| 206 | * @return a fixed-size map backed by that map | |
| 207 | * @throws NullPointerException if the SortedMap is null | |
| 208 | */ | |
| 209 | public static <K, V> SortedMap<K, V> fixedSizeSortedMap(final SortedMap<K, V> map) { | |
| 210 |
1
1. fixedSizeSortedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::fixedSizeSortedMap → NO_COVERAGE |
return FixedSizeSortedMap.fixedSizeSortedMap(map); |
| 211 | } | |
| 212 | ||
| 213 | /** | |
| 214 | * Gets a Boolean from a Map in a null-safe manner. | |
| 215 | * <p> | |
| 216 | * If the value is a {@code Boolean} it is returned directly. If the value is a {@code String} and it | |
| 217 | * equals 'true' ignoring case then {@code true} is returned, otherwise {@code false}. If the value is a | |
| 218 | * {@code Number} an integer zero value returns {@code false} and non-zero returns {@code true}. | |
| 219 | * Otherwise, {@code null} is returned. | |
| 220 | * | |
| 221 | * @param <K> the key type | |
| 222 | * @param map the map to use | |
| 223 | * @param key the key to look up | |
| 224 | * @return the value in the Map as a Boolean, {@code null} if null map input | |
| 225 | */ | |
| 226 | public static <K> Boolean getBoolean(final Map<? super K, ?> map, final K key) { | |
| 227 |
1
1. getBoolean : negated conditional → KILLED |
if (map != null) { |
| 228 | final Object answer = map.get(key); | |
| 229 |
1
1. getBoolean : negated conditional → KILLED |
if (answer != null) { |
| 230 |
1
1. getBoolean : negated conditional → KILLED |
if (answer instanceof Boolean) { |
| 231 |
2
1. getBoolean : replaced Boolean return with True for org/apache/commons/collections4/MapUtils::getBoolean → SURVIVED 2. getBoolean : replaced Boolean return with False for org/apache/commons/collections4/MapUtils::getBoolean → KILLED |
return (Boolean) answer; |
| 232 | } | |
| 233 |
1
1. getBoolean : negated conditional → KILLED |
if (answer instanceof String) { |
| 234 |
2
1. getBoolean : replaced Boolean return with True for org/apache/commons/collections4/MapUtils::getBoolean → SURVIVED 2. getBoolean : replaced Boolean return with False for org/apache/commons/collections4/MapUtils::getBoolean → KILLED |
return Boolean.valueOf((String) answer); |
| 235 | } | |
| 236 |
1
1. getBoolean : negated conditional → KILLED |
if (answer instanceof Number) { |
| 237 | final Number n = (Number) answer; | |
| 238 |
3
1. getBoolean : replaced Boolean return with False for org/apache/commons/collections4/MapUtils::getBoolean → KILLED 2. getBoolean : replaced Boolean return with True for org/apache/commons/collections4/MapUtils::getBoolean → KILLED 3. getBoolean : negated conditional → KILLED |
return n.intValue() != 0 ? Boolean.TRUE : Boolean.FALSE; |
| 239 | } | |
| 240 | } | |
| 241 | } | |
| 242 |
2
1. getBoolean : replaced Boolean return with False for org/apache/commons/collections4/MapUtils::getBoolean → KILLED 2. getBoolean : replaced Boolean return with True for org/apache/commons/collections4/MapUtils::getBoolean → KILLED |
return null; |
| 243 | } | |
| 244 | ||
| 245 | /** | |
| 246 | * Looks up the given key in the given map, converting the result into a boolean, using the default value if the | |
| 247 | * conversion fails. | |
| 248 | * | |
| 249 | * @param <K> the key type | |
| 250 | * @param map the map whose value to look up | |
| 251 | * @param key the key of the value to look up in that map | |
| 252 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 253 | * @return the value in the map as a boolean, or defaultValue if the original value is null, the map is null or the | |
| 254 | * boolean conversion fails | |
| 255 | */ | |
| 256 | public static <K> Boolean getBoolean(final Map<? super K, ?> map, final K key, final Boolean defaultValue) { | |
| 257 |
2
1. getBoolean : replaced Boolean return with True for org/apache/commons/collections4/MapUtils::getBoolean → SURVIVED 2. getBoolean : replaced Boolean return with False for org/apache/commons/collections4/MapUtils::getBoolean → KILLED |
return applyDefaultValue(map, key, MapUtils::getBoolean, defaultValue); |
| 258 | } | |
| 259 | ||
| 260 | /** | |
| 261 | * Looks up the given key in the given map, converting the result into a boolean, using the defaultFunction to | |
| 262 | * produce the default value if the conversion fails. | |
| 263 | * | |
| 264 | * @param <K> the key type | |
| 265 | * @param map the map whose value to look up | |
| 266 | * @param key the key of the value to look up in that map | |
| 267 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 268 | * @return the value in the map as a boolean, or defaultValue produced by the defaultFunction if the original value | |
| 269 | * is null, the map is null or the boolean conversion fails | |
| 270 | * @since 4.5 | |
| 271 | */ | |
| 272 | public static <K> Boolean getBoolean(final Map<? super K, ?> map, final K key, | |
| 273 | final Function<K, Boolean> defaultFunction) { | |
| 274 |
2
1. getBoolean : replaced Boolean return with False for org/apache/commons/collections4/MapUtils::getBoolean → KILLED 2. getBoolean : replaced Boolean return with True for org/apache/commons/collections4/MapUtils::getBoolean → KILLED |
return applyDefaultFunction(map, key, MapUtils::getBoolean, defaultFunction); |
| 275 | } | |
| 276 | ||
| 277 | // Type safe primitive getters | |
| 278 | // ------------------------------------------------------------------------- | |
| 279 | /** | |
| 280 | * Gets a boolean from a Map in a null-safe manner. | |
| 281 | * <p> | |
| 282 | * If the value is a {@code Boolean} its value is returned. If the value is a {@code String} and it equals | |
| 283 | * 'true' ignoring case then {@code true} is returned, otherwise {@code false}. If the value is a | |
| 284 | * {@code Number} an integer zero value returns {@code false} and non-zero returns {@code true}. | |
| 285 | * Otherwise, {@code false} is returned. | |
| 286 | * </p> | |
| 287 | * | |
| 288 | * @param <K> the key type | |
| 289 | * @param map the map to use | |
| 290 | * @param key the key to look up | |
| 291 | * @return the value in the Map as a Boolean, {@code false} if null map input | |
| 292 | */ | |
| 293 | public static <K> boolean getBooleanValue(final Map<? super K, ?> map, final K key) { | |
| 294 |
2
1. getBooleanValue : replaced boolean return with false for org/apache/commons/collections4/MapUtils::getBooleanValue → KILLED 2. getBooleanValue : replaced boolean return with true for org/apache/commons/collections4/MapUtils::getBooleanValue → KILLED |
return Boolean.TRUE.equals(getBoolean(map, key)); |
| 295 | } | |
| 296 | ||
| 297 | // Type safe primitive getters with default values | |
| 298 | // ------------------------------------------------------------------------- | |
| 299 | /** | |
| 300 | * Gets a boolean from a Map in a null-safe manner, using the default value if the conversion fails. | |
| 301 | * <p> | |
| 302 | * If the value is a {@code Boolean} its value is returned. If the value is a {@code String} and it equals | |
| 303 | * 'true' ignoring case then {@code true} is returned, otherwise {@code false}. If the value is a | |
| 304 | * {@code Number} an integer zero value returns {@code false} and non-zero returns {@code true}. | |
| 305 | * Otherwise, {@code defaultValue} is returned. | |
| 306 | * </p> | |
| 307 | * | |
| 308 | * @param <K> the key type | |
| 309 | * @param map the map to use | |
| 310 | * @param key the key to look up | |
| 311 | * @param defaultValue return if the value is null or if the conversion fails | |
| 312 | * @return the value in the Map as a Boolean, {@code defaultValue} if null map input | |
| 313 | */ | |
| 314 | public static <K> boolean getBooleanValue(final Map<? super K, ?> map, final K key, final boolean defaultValue) { | |
| 315 |
2
1. getBooleanValue : replaced boolean return with true for org/apache/commons/collections4/MapUtils::getBooleanValue → SURVIVED 2. getBooleanValue : replaced boolean return with false for org/apache/commons/collections4/MapUtils::getBooleanValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getBoolean, defaultValue).booleanValue(); |
| 316 | } | |
| 317 | ||
| 318 | /** | |
| 319 | * Gets a boolean from a Map in a null-safe manner, using the default value produced by the defaultFunction if the | |
| 320 | * conversion fails. | |
| 321 | * <p> | |
| 322 | * If the value is a {@code Boolean} its value is returned. If the value is a {@code String} and it equals | |
| 323 | * 'true' ignoring case then {@code true} is returned, otherwise {@code false}. If the value is a | |
| 324 | * {@code Number} an integer zero value returns {@code false} and non-zero returns {@code true}. | |
| 325 | * Otherwise, defaultValue produced by the {@code defaultFunction} is returned. | |
| 326 | * </p> | |
| 327 | * | |
| 328 | * @param <K> the key type | |
| 329 | * @param map the map to use | |
| 330 | * @param key the key to look up | |
| 331 | * @param defaultFunction produce the default value to return if the value is null or if the conversion fails | |
| 332 | * @return the value in the Map as a Boolean, default value produced by the {@code defaultFunction} if null map | |
| 333 | * input | |
| 334 | * @since 4.5 | |
| 335 | */ | |
| 336 | public static <K> boolean getBooleanValue(final Map<? super K, ?> map, final K key, | |
| 337 | final Function<K, Boolean> defaultFunction) { | |
| 338 |
2
1. getBooleanValue : replaced boolean return with false for org/apache/commons/collections4/MapUtils::getBooleanValue → KILLED 2. getBooleanValue : replaced boolean return with true for org/apache/commons/collections4/MapUtils::getBooleanValue → KILLED |
return applyDefaultFunction(map, key, MapUtils::getBoolean, defaultFunction, false).booleanValue(); |
| 339 | } | |
| 340 | ||
| 341 | /** | |
| 342 | * Gets a Byte from a Map in a null-safe manner. | |
| 343 | * <p> | |
| 344 | * The Byte is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 345 | * </p> | |
| 346 | * | |
| 347 | * @param <K> the key type | |
| 348 | * @param map the map to use | |
| 349 | * @param key the key to look up | |
| 350 | * @return the value in the Map as a Byte, {@code null} if null map input | |
| 351 | */ | |
| 352 | public static <K> Byte getByte(final Map<? super K, ?> map, final K key) { | |
| 353 | final Number answer = getNumber(map, key); | |
| 354 |
1
1. getByte : negated conditional → KILLED |
if (answer == null) { |
| 355 | return null; | |
| 356 | } | |
| 357 |
1
1. getByte : negated conditional → KILLED |
if (answer instanceof Byte) { |
| 358 |
1
1. getByte : replaced return value with null for org/apache/commons/collections4/MapUtils::getByte → KILLED |
return (Byte) answer; |
| 359 | } | |
| 360 |
1
1. getByte : replaced return value with null for org/apache/commons/collections4/MapUtils::getByte → SURVIVED |
return Byte.valueOf(answer.byteValue()); |
| 361 | } | |
| 362 | ||
| 363 | /** | |
| 364 | * Looks up the given key in the given map, converting the result into a byte, using the default value if the | |
| 365 | * conversion fails. | |
| 366 | * | |
| 367 | * @param <K> the key type | |
| 368 | * @param map the map whose value to look up | |
| 369 | * @param key the key of the value to look up in that map | |
| 370 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 371 | * @return the value in the map as a number, or defaultValue if the original value is null, the map is null or the | |
| 372 | * number conversion fails | |
| 373 | */ | |
| 374 | public static <K> Byte getByte(final Map<? super K, ?> map, final K key, final Byte defaultValue) { | |
| 375 |
1
1. getByte : replaced return value with null for org/apache/commons/collections4/MapUtils::getByte → KILLED |
return applyDefaultValue(map, key, MapUtils::getByte, defaultValue); |
| 376 | } | |
| 377 | ||
| 378 | /** | |
| 379 | * Looks up the given key in the given map, converting the result into a byte, using the defaultFunction to produce | |
| 380 | * the default value if the conversion fails. | |
| 381 | * | |
| 382 | * @param <K> the key type | |
| 383 | * @param map the map whose value to look up | |
| 384 | * @param key the key of the value to look up in that map | |
| 385 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 386 | * @return the value in the map as a number, or defaultValue produced by the defaultFunction if the original value | |
| 387 | * is null, the map is null or the number conversion fails | |
| 388 | * @since 4.5 | |
| 389 | */ | |
| 390 | public static <K> Byte getByte(final Map<? super K, ?> map, final K key, final Function<K, Byte> defaultFunction) { | |
| 391 |
1
1. getByte : replaced return value with null for org/apache/commons/collections4/MapUtils::getByte → KILLED |
return applyDefaultFunction(map, key, MapUtils::getByte, defaultFunction); |
| 392 | } | |
| 393 | ||
| 394 | /** | |
| 395 | * Gets a byte from a Map in a null-safe manner. | |
| 396 | * <p> | |
| 397 | * The byte is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 398 | * </p> | |
| 399 | * | |
| 400 | * @param <K> the key type | |
| 401 | * @param map the map to use | |
| 402 | * @param key the key to look up | |
| 403 | * @return the value in the Map as a byte, {@code 0} if null map input | |
| 404 | */ | |
| 405 | public static <K> byte getByteValue(final Map<? super K, ?> map, final K key) { | |
| 406 |
1
1. getByteValue : replaced byte return with 0 for org/apache/commons/collections4/MapUtils::getByteValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getByte, 0).byteValue(); |
| 407 | } | |
| 408 | ||
| 409 | /** | |
| 410 | * Gets a byte from a Map in a null-safe manner, using the default value if the conversion fails. | |
| 411 | * <p> | |
| 412 | * The byte is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 413 | * </p> | |
| 414 | * | |
| 415 | * @param <K> the key type | |
| 416 | * @param map the map to use | |
| 417 | * @param key the key to look up | |
| 418 | * @param defaultValue return if the value is null or if the conversion fails | |
| 419 | * @return the value in the Map as a byte, {@code defaultValue} if null map input | |
| 420 | */ | |
| 421 | public static <K> byte getByteValue(final Map<? super K, ?> map, final K key, final byte defaultValue) { | |
| 422 |
1
1. getByteValue : replaced byte return with 0 for org/apache/commons/collections4/MapUtils::getByteValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getByte, defaultValue).byteValue(); |
| 423 | } | |
| 424 | ||
| 425 | /** | |
| 426 | * Gets a byte from a Map in a null-safe manner, using the default value produced by the defaultFunction if the | |
| 427 | * conversion fails. | |
| 428 | * <p> | |
| 429 | * The byte is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 430 | * </p> | |
| 431 | * | |
| 432 | * @param <K> the key type | |
| 433 | * @param map the map to use | |
| 434 | * @param key the key to look up | |
| 435 | * @param defaultFunction produce the default value to return if the value is null or if the conversion fails | |
| 436 | * @return the value in the Map as a byte, default value produced by the {@code defaultFunction} if null map | |
| 437 | * input | |
| 438 | * @since 4.5 | |
| 439 | */ | |
| 440 | public static <K> byte getByteValue(final Map<? super K, ?> map, final K key, | |
| 441 | final Function<K, Byte> defaultFunction) { | |
| 442 |
1
1. getByteValue : replaced byte return with 0 for org/apache/commons/collections4/MapUtils::getByteValue → KILLED |
return applyDefaultFunction(map, key, MapUtils::getByte, defaultFunction, (byte) 0).byteValue(); |
| 443 | } | |
| 444 | ||
| 445 | /** | |
| 446 | * Gets a Double from a Map in a null-safe manner. | |
| 447 | * <p> | |
| 448 | * The Double is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 449 | * </p> | |
| 450 | * | |
| 451 | * @param <K> the key type | |
| 452 | * @param map the map to use | |
| 453 | * @param key the key to look up | |
| 454 | * @return the value in the Map as a Double, {@code null} if null map input | |
| 455 | */ | |
| 456 | public static <K> Double getDouble(final Map<? super K, ?> map, final K key) { | |
| 457 | final Number answer = getNumber(map, key); | |
| 458 |
1
1. getDouble : negated conditional → KILLED |
if (answer == null) { |
| 459 |
1
1. getDouble : replaced Double return value with 0 for org/apache/commons/collections4/MapUtils::getDouble → KILLED |
return null; |
| 460 | } | |
| 461 |
1
1. getDouble : negated conditional → KILLED |
if (answer instanceof Double) { |
| 462 |
1
1. getDouble : replaced Double return value with 0 for org/apache/commons/collections4/MapUtils::getDouble → KILLED |
return (Double) answer; |
| 463 | } | |
| 464 |
1
1. getDouble : replaced Double return value with 0 for org/apache/commons/collections4/MapUtils::getDouble → KILLED |
return Double.valueOf(answer.doubleValue()); |
| 465 | } | |
| 466 | ||
| 467 | /** | |
| 468 | * Looks up the given key in the given map, converting the result into a double, using the default value if the | |
| 469 | * conversion fails. | |
| 470 | * | |
| 471 | * @param <K> the key type | |
| 472 | * @param map the map whose value to look up | |
| 473 | * @param key the key of the value to look up in that map | |
| 474 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 475 | * @return the value in the map as a number, or defaultValue if the original value is null, the map is null or the | |
| 476 | * number conversion fails | |
| 477 | */ | |
| 478 | public static <K> Double getDouble(final Map<? super K, ?> map, final K key, final Double defaultValue) { | |
| 479 |
1
1. getDouble : replaced Double return value with 0 for org/apache/commons/collections4/MapUtils::getDouble → KILLED |
return applyDefaultValue(map, key, MapUtils::getDouble, defaultValue); |
| 480 | } | |
| 481 | ||
| 482 | /** | |
| 483 | * Looks up the given key in the given map, converting the result into a double, using the defaultFunction to | |
| 484 | * produce the default value if the conversion fails. | |
| 485 | * | |
| 486 | * @param <K> the key type | |
| 487 | * @param map the map whose value to look up | |
| 488 | * @param key the key of the value to look up in that map | |
| 489 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 490 | * @return the value in the map as a number, or defaultValue produced by the defaultFunction if the original value | |
| 491 | * is null, the map is null or the number conversion fails | |
| 492 | * @since 4.5 | |
| 493 | */ | |
| 494 | public static <K> Double getDouble(final Map<? super K, ?> map, final K key, | |
| 495 | final Function<K, Double> defaultFunction) { | |
| 496 |
1
1. getDouble : replaced Double return value with 0 for org/apache/commons/collections4/MapUtils::getDouble → KILLED |
return applyDefaultFunction(map, key, MapUtils::getDouble, defaultFunction); |
| 497 | } | |
| 498 | ||
| 499 | /** | |
| 500 | * Gets a double from a Map in a null-safe manner. | |
| 501 | * <p> | |
| 502 | * The double is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 503 | * </p> | |
| 504 | * | |
| 505 | * @param <K> the key type | |
| 506 | * @param map the map to use | |
| 507 | * @param key the key to look up | |
| 508 | * @return the value in the Map as a double, {@code 0.0} if null map input | |
| 509 | */ | |
| 510 | public static <K> double getDoubleValue(final Map<? super K, ?> map, final K key) { | |
| 511 |
1
1. getDoubleValue : replaced double return with 0.0d for org/apache/commons/collections4/MapUtils::getDoubleValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getDouble, 0d).doubleValue(); |
| 512 | } | |
| 513 | ||
| 514 | /** | |
| 515 | * Gets a double from a Map in a null-safe manner, using the default value if the conversion fails. | |
| 516 | * <p> | |
| 517 | * The double is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 518 | * </p> | |
| 519 | * | |
| 520 | * @param <K> the key type | |
| 521 | * @param map the map to use | |
| 522 | * @param key the key to look up | |
| 523 | * @param defaultValue return if the value is null or if the conversion fails | |
| 524 | * @return the value in the Map as a double, {@code defaultValue} if null map input | |
| 525 | */ | |
| 526 | public static <K> double getDoubleValue(final Map<? super K, ?> map, final K key, final double defaultValue) { | |
| 527 |
1
1. getDoubleValue : replaced double return with 0.0d for org/apache/commons/collections4/MapUtils::getDoubleValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getDouble, defaultValue).doubleValue(); |
| 528 | } | |
| 529 | ||
| 530 | /** | |
| 531 | * Gets a double from a Map in a null-safe manner, using the default value produced by the defaultFunction if the | |
| 532 | * conversion fails. | |
| 533 | * <p> | |
| 534 | * The double is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 535 | * </p> | |
| 536 | * | |
| 537 | * @param <K> the key type | |
| 538 | * @param map the map to use | |
| 539 | * @param key the key to look up | |
| 540 | * @param defaultFunction produce the default value to return if the value is null or if the conversion fails | |
| 541 | * @return the value in the Map as a double, default value produced by the {@code defaultFunction} if null map | |
| 542 | * input | |
| 543 | * @since 4.5 | |
| 544 | */ | |
| 545 | public static <K> double getDoubleValue(final Map<? super K, ?> map, final K key, | |
| 546 | final Function<K, Double> defaultFunction) { | |
| 547 |
1
1. getDoubleValue : replaced double return with 0.0d for org/apache/commons/collections4/MapUtils::getDoubleValue → KILLED |
return applyDefaultFunction(map, key, MapUtils::getDouble, defaultFunction, 0d).doubleValue(); |
| 548 | } | |
| 549 | ||
| 550 | /** | |
| 551 | * Gets a Float from a Map in a null-safe manner. | |
| 552 | * <p> | |
| 553 | * The Float is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 554 | * </p> | |
| 555 | * | |
| 556 | * @param <K> the key type | |
| 557 | * @param map the map to use | |
| 558 | * @param key the key to look up | |
| 559 | * @return the value in the Map as a Float, {@code null} if null map input | |
| 560 | */ | |
| 561 | public static <K> Float getFloat(final Map<? super K, ?> map, final K key) { | |
| 562 | final Number answer = getNumber(map, key); | |
| 563 |
1
1. getFloat : negated conditional → KILLED |
if (answer == null) { |
| 564 |
1
1. getFloat : replaced Float return value with 0 for org/apache/commons/collections4/MapUtils::getFloat → KILLED |
return null; |
| 565 | } | |
| 566 |
1
1. getFloat : negated conditional → KILLED |
if (answer instanceof Float) { |
| 567 |
1
1. getFloat : replaced Float return value with 0 for org/apache/commons/collections4/MapUtils::getFloat → KILLED |
return (Float) answer; |
| 568 | } | |
| 569 |
1
1. getFloat : replaced Float return value with 0 for org/apache/commons/collections4/MapUtils::getFloat → KILLED |
return Float.valueOf(answer.floatValue()); |
| 570 | } | |
| 571 | ||
| 572 | /** | |
| 573 | * Looks up the given key in the given map, converting the result into a float, using the default value if the | |
| 574 | * conversion fails. | |
| 575 | * | |
| 576 | * @param <K> the key type | |
| 577 | * @param map the map whose value to look up | |
| 578 | * @param key the key of the value to look up in that map | |
| 579 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 580 | * @return the value in the map as a number, or defaultValue if the original value is null, the map is null or the | |
| 581 | * number conversion fails | |
| 582 | */ | |
| 583 | public static <K> Float getFloat(final Map<? super K, ?> map, final K key, final Float defaultValue) { | |
| 584 |
1
1. getFloat : replaced Float return value with 0 for org/apache/commons/collections4/MapUtils::getFloat → KILLED |
return applyDefaultValue(map, key, MapUtils::getFloat, defaultValue); |
| 585 | } | |
| 586 | ||
| 587 | /** | |
| 588 | * Looks up the given key in the given map, converting the result into a float, using the defaultFunction to produce | |
| 589 | * the default value if the conversion fails. | |
| 590 | * | |
| 591 | * @param <K> the key type | |
| 592 | * @param map the map whose value to look up | |
| 593 | * @param key the key of the value to look up in that map | |
| 594 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 595 | * @return the value in the map as a number, or defaultValue produced by the defaultFunction if the original value | |
| 596 | * is null, the map is null or the number conversion fails | |
| 597 | * @since 4.5 | |
| 598 | */ | |
| 599 | public static <K> Float getFloat(final Map<? super K, ?> map, final K key, | |
| 600 | final Function<K, Float> defaultFunction) { | |
| 601 |
1
1. getFloat : replaced Float return value with 0 for org/apache/commons/collections4/MapUtils::getFloat → KILLED |
return applyDefaultFunction(map, key, MapUtils::getFloat, defaultFunction); |
| 602 | } | |
| 603 | ||
| 604 | /** | |
| 605 | * Gets a float from a Map in a null-safe manner. | |
| 606 | * <p> | |
| 607 | * The float is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 608 | * </p> | |
| 609 | * | |
| 610 | * @param <K> the key type | |
| 611 | * @param map the map to use | |
| 612 | * @param key the key to look up | |
| 613 | * @return the value in the Map as a float, {@code 0.0F} if null map input | |
| 614 | */ | |
| 615 | public static <K> float getFloatValue(final Map<? super K, ?> map, final K key) { | |
| 616 |
1
1. getFloatValue : replaced float return with 0.0f for org/apache/commons/collections4/MapUtils::getFloatValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getFloat, 0f).floatValue(); |
| 617 | } | |
| 618 | ||
| 619 | /** | |
| 620 | * Gets a float from a Map in a null-safe manner, using the default value if the conversion fails. | |
| 621 | * <p> | |
| 622 | * The float is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 623 | * </p> | |
| 624 | * | |
| 625 | * @param <K> the key type | |
| 626 | * @param map the map to use | |
| 627 | * @param key the key to look up | |
| 628 | * @param defaultValue return if the value is null or if the conversion fails | |
| 629 | * @return the value in the Map as a float, {@code defaultValue} if null map input | |
| 630 | */ | |
| 631 | public static <K> float getFloatValue(final Map<? super K, ?> map, final K key, final float defaultValue) { | |
| 632 |
1
1. getFloatValue : replaced float return with 0.0f for org/apache/commons/collections4/MapUtils::getFloatValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getFloat, defaultValue).floatValue(); |
| 633 | } | |
| 634 | ||
| 635 | /** | |
| 636 | * Gets a float from a Map in a null-safe manner, using the default value produced by the defaultFunction if the | |
| 637 | * conversion fails. | |
| 638 | * <p> | |
| 639 | * The float is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 640 | * </p> | |
| 641 | * | |
| 642 | * @param <K> the key type | |
| 643 | * @param map the map to use | |
| 644 | * @param key the key to look up | |
| 645 | * @param defaultFunction produce the default value to return if the value is null or if the conversion fails | |
| 646 | * @return the value in the Map as a float, default value produced by the {@code defaultFunction} if null map | |
| 647 | * input | |
| 648 | * @since 4.5 | |
| 649 | */ | |
| 650 | public static <K> float getFloatValue(final Map<? super K, ?> map, final K key, | |
| 651 | final Function<K, Float> defaultFunction) { | |
| 652 |
1
1. getFloatValue : replaced float return with 0.0f for org/apache/commons/collections4/MapUtils::getFloatValue → KILLED |
return applyDefaultFunction(map, key, MapUtils::getFloat, defaultFunction, 0f).floatValue(); |
| 653 | } | |
| 654 | ||
| 655 | /** | |
| 656 | * Gets a Integer from a Map in a null-safe manner. | |
| 657 | * <p> | |
| 658 | * The Integer is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 659 | * </p> | |
| 660 | * | |
| 661 | * @param <K> the key type | |
| 662 | * @param map the map to use | |
| 663 | * @param key the key to look up | |
| 664 | * @return the value in the Map as a Integer, {@code null} if null map input | |
| 665 | */ | |
| 666 | public static <K> Integer getInteger(final Map<? super K, ?> map, final K key) { | |
| 667 | final Number answer = getNumber(map, key); | |
| 668 |
1
1. getInteger : negated conditional → KILLED |
if (answer == null) { |
| 669 |
1
1. getInteger : replaced Integer return value with 0 for org/apache/commons/collections4/MapUtils::getInteger → SURVIVED |
return null; |
| 670 | } | |
| 671 |
1
1. getInteger : negated conditional → KILLED |
if (answer instanceof Integer) { |
| 672 |
1
1. getInteger : replaced Integer return value with 0 for org/apache/commons/collections4/MapUtils::getInteger → KILLED |
return (Integer) answer; |
| 673 | } | |
| 674 |
1
1. getInteger : replaced Integer return value with 0 for org/apache/commons/collections4/MapUtils::getInteger → KILLED |
return Integer.valueOf(answer.intValue()); |
| 675 | } | |
| 676 | ||
| 677 | /** | |
| 678 | * Looks up the given key in the given map, converting the result into an integer, using the defaultFunction to | |
| 679 | * produce the default value if the conversion fails. | |
| 680 | * | |
| 681 | * @param <K> the key type | |
| 682 | * @param map the map whose value to look up | |
| 683 | * @param key the key of the value to look up in that map | |
| 684 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 685 | * @return the value in the map as a number, or defaultValue produced by the defaultFunction if the original value | |
| 686 | * is null, the map is null or the number conversion fails | |
| 687 | * @since 4.5 | |
| 688 | */ | |
| 689 | public static <K> Integer getInteger(final Map<? super K, ?> map, final K key, | |
| 690 | final Function<K, Integer> defaultFunction) { | |
| 691 |
1
1. getInteger : replaced Integer return value with 0 for org/apache/commons/collections4/MapUtils::getInteger → SURVIVED |
return applyDefaultFunction(map, key, MapUtils::getInteger, defaultFunction); |
| 692 | } | |
| 693 | ||
| 694 | /** | |
| 695 | * Looks up the given key in the given map, converting the result into an integer, using the default value if the | |
| 696 | * conversion fails. | |
| 697 | * | |
| 698 | * @param <K> the key type | |
| 699 | * @param map the map whose value to look up | |
| 700 | * @param key the key of the value to look up in that map | |
| 701 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 702 | * @return the value in the map as a number, or defaultValue if the original value is null, the map is null or the | |
| 703 | * number conversion fails | |
| 704 | */ | |
| 705 | public static <K> Integer getInteger(final Map<? super K, ?> map, final K key, final Integer defaultValue) { | |
| 706 |
1
1. getInteger : replaced Integer return value with 0 for org/apache/commons/collections4/MapUtils::getInteger → KILLED |
return applyDefaultValue(map, key, MapUtils::getInteger, defaultValue); |
| 707 | } | |
| 708 | ||
| 709 | /** | |
| 710 | * Gets an int from a Map in a null-safe manner. | |
| 711 | * <p> | |
| 712 | * The int is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 713 | * </p> | |
| 714 | * | |
| 715 | * @param <K> the key type | |
| 716 | * @param map the map to use | |
| 717 | * @param key the key to look up | |
| 718 | * @return the value in the Map as an int, {@code 0} if null map input | |
| 719 | */ | |
| 720 | public static <K> int getIntValue(final Map<? super K, ?> map, final K key) { | |
| 721 |
1
1. getIntValue : replaced int return with 0 for org/apache/commons/collections4/MapUtils::getIntValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getInteger, 0).intValue(); |
| 722 | } | |
| 723 | ||
| 724 | /** | |
| 725 | * Gets an int from a Map in a null-safe manner, using the default value produced by the defaultFunction if the | |
| 726 | * conversion fails. | |
| 727 | * <p> | |
| 728 | * The int is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 729 | * </p> | |
| 730 | * | |
| 731 | * @param <K> the key type | |
| 732 | * @param map the map to use | |
| 733 | * @param key the key to look up | |
| 734 | * @param defaultFunction produce the default value to return if the value is null or if the conversion fails | |
| 735 | * @return the value in the Map as an int, default value produced by the {@code defaultFunction} if null map | |
| 736 | * input | |
| 737 | * @since 4.5 | |
| 738 | */ | |
| 739 | public static <K> int getIntValue(final Map<? super K, ?> map, final K key, | |
| 740 | final Function<K, Integer> defaultFunction) { | |
| 741 |
1
1. getIntValue : replaced int return with 0 for org/apache/commons/collections4/MapUtils::getIntValue → SURVIVED |
return applyDefaultFunction(map, key, MapUtils::getInteger, defaultFunction, 0).byteValue(); |
| 742 | } | |
| 743 | ||
| 744 | /** | |
| 745 | * Gets an int from a Map in a null-safe manner, using the default value if the conversion fails. | |
| 746 | * <p> | |
| 747 | * The int is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 748 | * </p> | |
| 749 | * | |
| 750 | * @param <K> the key type | |
| 751 | * @param map the map to use | |
| 752 | * @param key the key to look up | |
| 753 | * @param defaultValue return if the value is null or if the conversion fails | |
| 754 | * @return the value in the Map as an int, {@code defaultValue} if null map input | |
| 755 | */ | |
| 756 | public static <K> int getIntValue(final Map<? super K, ?> map, final K key, final int defaultValue) { | |
| 757 |
1
1. getIntValue : replaced int return with 0 for org/apache/commons/collections4/MapUtils::getIntValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getInteger, defaultValue).intValue(); |
| 758 | } | |
| 759 | ||
| 760 | /** | |
| 761 | * Gets a Long from a Map in a null-safe manner. | |
| 762 | * <p> | |
| 763 | * The Long is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 764 | * </p> | |
| 765 | * | |
| 766 | * @param <K> the key type | |
| 767 | * @param map the map to use | |
| 768 | * @param key the key to look up | |
| 769 | * @return the value in the Map as a Long, {@code null} if null map input | |
| 770 | */ | |
| 771 | public static <K> Long getLong(final Map<? super K, ?> map, final K key) { | |
| 772 | final Number answer = getNumber(map, key); | |
| 773 |
1
1. getLong : negated conditional → KILLED |
if (answer == null) { |
| 774 |
1
1. getLong : replaced Long return value with 0L for org/apache/commons/collections4/MapUtils::getLong → KILLED |
return null; |
| 775 | } | |
| 776 |
1
1. getLong : negated conditional → SURVIVED |
if (answer instanceof Long) { |
| 777 |
1
1. getLong : replaced Long return value with 0L for org/apache/commons/collections4/MapUtils::getLong → KILLED |
return (Long) answer; |
| 778 | } | |
| 779 |
1
1. getLong : replaced Long return value with 0L for org/apache/commons/collections4/MapUtils::getLong → NO_COVERAGE |
return Long.valueOf(answer.longValue()); |
| 780 | } | |
| 781 | ||
| 782 | /** | |
| 783 | * Looks up the given key in the given map, converting the result into a Long, using the defaultFunction to produce | |
| 784 | * the default value if the conversion fails. | |
| 785 | * | |
| 786 | * @param <K> the key type | |
| 787 | * @param map the map whose value to look up | |
| 788 | * @param key the key of the value to look up in that map | |
| 789 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 790 | * @return the value in the map as a number, or defaultValue produced by the defaultFunction if the original value | |
| 791 | * is null, the map is null or the number conversion fails | |
| 792 | * @since 4.5 | |
| 793 | */ | |
| 794 | public static <K> Long getLong(final Map<? super K, ?> map, final K key, final Function<K, Long> defaultFunction) { | |
| 795 |
1
1. getLong : replaced Long return value with 0L for org/apache/commons/collections4/MapUtils::getLong → KILLED |
return applyDefaultFunction(map, key, MapUtils::getLong, defaultFunction); |
| 796 | } | |
| 797 | ||
| 798 | /** | |
| 799 | * Looks up the given key in the given map, converting the result into a long, using the default value if the | |
| 800 | * conversion fails. | |
| 801 | * | |
| 802 | * @param <K> the key type | |
| 803 | * @param map the map whose value to look up | |
| 804 | * @param key the key of the value to look up in that map | |
| 805 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 806 | * @return the value in the map as a number, or defaultValue if the original value is null, the map is null or the | |
| 807 | * number conversion fails | |
| 808 | */ | |
| 809 | public static <K> Long getLong(final Map<? super K, ?> map, final K key, final Long defaultValue) { | |
| 810 |
1
1. getLong : replaced Long return value with 0L for org/apache/commons/collections4/MapUtils::getLong → KILLED |
return applyDefaultValue(map, key, MapUtils::getLong, defaultValue); |
| 811 | } | |
| 812 | ||
| 813 | /** | |
| 814 | * Gets a long from a Map in a null-safe manner. | |
| 815 | * <p> | |
| 816 | * The long is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 817 | * </p> | |
| 818 | * | |
| 819 | * @param <K> the key type | |
| 820 | * @param map the map to use | |
| 821 | * @param key the key to look up | |
| 822 | * @return the value in the Map as a long, {@code 0L} if null map input | |
| 823 | */ | |
| 824 | public static <K> long getLongValue(final Map<? super K, ?> map, final K key) { | |
| 825 |
1
1. getLongValue : replaced long return with 0 for org/apache/commons/collections4/MapUtils::getLongValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getLong, 0L).longValue(); |
| 826 | } | |
| 827 | ||
| 828 | /** | |
| 829 | * Gets a long from a Map in a null-safe manner, using the default value produced by the defaultFunction if the | |
| 830 | * conversion fails. | |
| 831 | * <p> | |
| 832 | * The long is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 833 | * </p> | |
| 834 | * | |
| 835 | * @param <K> the key type | |
| 836 | * @param map the map to use | |
| 837 | * @param key the key to look up | |
| 838 | * @param defaultFunction produce the default value to return if the value is null or if the conversion fails | |
| 839 | * @return the value in the Map as a long, default value produced by the {@code defaultFunction} if null map | |
| 840 | * input | |
| 841 | * @since 4.5 | |
| 842 | */ | |
| 843 | public static <K> long getLongValue(final Map<? super K, ?> map, final K key, | |
| 844 | final Function<K, Long> defaultFunction) { | |
| 845 |
1
1. getLongValue : replaced long return with 0 for org/apache/commons/collections4/MapUtils::getLongValue → KILLED |
return applyDefaultFunction(map, key, MapUtils::getLong, defaultFunction, 0L).byteValue(); |
| 846 | } | |
| 847 | ||
| 848 | /** | |
| 849 | * Gets a long from a Map in a null-safe manner, using the default value if the conversion fails. | |
| 850 | * <p> | |
| 851 | * The long is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 852 | * </p> | |
| 853 | * | |
| 854 | * @param <K> the key type | |
| 855 | * @param map the map to use | |
| 856 | * @param key the key to look up | |
| 857 | * @param defaultValue return if the value is null or if the conversion fails | |
| 858 | * @return the value in the Map as a long, {@code defaultValue} if null map input | |
| 859 | */ | |
| 860 | public static <K> long getLongValue(final Map<? super K, ?> map, final K key, final long defaultValue) { | |
| 861 |
1
1. getLongValue : replaced long return with 0 for org/apache/commons/collections4/MapUtils::getLongValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getLong, defaultValue).longValue(); |
| 862 | } | |
| 863 | ||
| 864 | /** | |
| 865 | * Gets a Map from a Map in a null-safe manner. | |
| 866 | * <p> | |
| 867 | * If the value returned from the specified map is not a Map then {@code null} is returned. | |
| 868 | * </p> | |
| 869 | * | |
| 870 | * @param <K> the key type | |
| 871 | * @param map the map to use | |
| 872 | * @param key the key to look up | |
| 873 | * @return the value in the Map as a Map, {@code null} if null map input | |
| 874 | */ | |
| 875 | public static <K> Map<?, ?> getMap(final Map<? super K, ?> map, final K key) { | |
| 876 |
1
1. getMap : negated conditional → KILLED |
if (map != null) { |
| 877 | final Object answer = map.get(key); | |
| 878 |
2
1. getMap : negated conditional → KILLED 2. getMap : negated conditional → KILLED |
if (answer != null && answer instanceof Map) { |
| 879 |
1
1. getMap : replaced return value with null for org/apache/commons/collections4/MapUtils::getMap → KILLED |
return (Map<?, ?>) answer; |
| 880 | } | |
| 881 | } | |
| 882 | return null; | |
| 883 | } | |
| 884 | ||
| 885 | /** | |
| 886 | * Looks up the given key in the given map, converting the result into a map, using the defaultFunction to produce | |
| 887 | * the default value if the conversion fails. | |
| 888 | * | |
| 889 | * @param <K> the key type | |
| 890 | * @param map the map whose value to look up | |
| 891 | * @param key the key of the value to look up in that map | |
| 892 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 893 | * @return the value in the map as a number, or defaultValue produced by the defaultFunction if the original value | |
| 894 | * is null, the map is null or the map conversion fails | |
| 895 | * @since 4.5 | |
| 896 | */ | |
| 897 | public static <K> Map<?, ?> getMap(final Map<? super K, ?> map, final K key, | |
| 898 | final Function<K, Map<?, ?>> defaultFunction) { | |
| 899 |
1
1. getMap : replaced return value with null for org/apache/commons/collections4/MapUtils::getMap → NO_COVERAGE |
return applyDefaultFunction(map, key, MapUtils::getMap, defaultFunction); |
| 900 | } | |
| 901 | ||
| 902 | /** | |
| 903 | * Looks up the given key in the given map, converting the result into a map, using the default value if the | |
| 904 | * conversion fails. | |
| 905 | * | |
| 906 | * @param <K> the key type | |
| 907 | * @param map the map whose value to look up | |
| 908 | * @param key the key of the value to look up in that map | |
| 909 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 910 | * @return the value in the map as a number, or defaultValue if the original value is null, the map is null or the | |
| 911 | * map conversion fails | |
| 912 | */ | |
| 913 | public static <K> Map<?, ?> getMap(final Map<? super K, ?> map, final K key, final Map<?, ?> defaultValue) { | |
| 914 |
1
1. getMap : replaced return value with null for org/apache/commons/collections4/MapUtils::getMap → KILLED |
return applyDefaultValue(map, key, MapUtils::getMap, defaultValue); |
| 915 | } | |
| 916 | ||
| 917 | /** | |
| 918 | * Gets a Number from a Map in a null-safe manner. | |
| 919 | * <p> | |
| 920 | * If the value is a {@code Number} it is returned directly. If the value is a {@code String} it is | |
| 921 | * converted using {@link NumberFormat#parse(String)} on the system default formatter returning {@code null} if | |
| 922 | * the conversion fails. Otherwise, {@code null} is returned. | |
| 923 | * </p> | |
| 924 | * | |
| 925 | * @param <K> the key type | |
| 926 | * @param map the map to use | |
| 927 | * @param key the key to look up | |
| 928 | * @return the value in the Map as a Number, {@code null} if null map input | |
| 929 | */ | |
| 930 | public static <K> Number getNumber(final Map<? super K, ?> map, final K key) { | |
| 931 |
1
1. getNumber : negated conditional → KILLED |
if (map != null) { |
| 932 | final Object answer = map.get(key); | |
| 933 |
1
1. getNumber : negated conditional → KILLED |
if (answer != null) { |
| 934 |
1
1. getNumber : negated conditional → KILLED |
if (answer instanceof Number) { |
| 935 |
1
1. getNumber : replaced return value with null for org/apache/commons/collections4/MapUtils::getNumber → KILLED |
return (Number) answer; |
| 936 | } | |
| 937 |
1
1. getNumber : negated conditional → KILLED |
if (answer instanceof String) { |
| 938 | try { | |
| 939 | final String text = (String) answer; | |
| 940 |
1
1. getNumber : replaced return value with null for org/apache/commons/collections4/MapUtils::getNumber → KILLED |
return NumberFormat.getInstance().parse(text); |
| 941 | } catch (final ParseException e) { // NOPMD | |
| 942 | // failure means null is returned | |
| 943 | } | |
| 944 | } | |
| 945 | } | |
| 946 | } | |
| 947 | return null; | |
| 948 | } | |
| 949 | ||
| 950 | /** | |
| 951 | * Looks up the given key in the given map, converting the result into a number, using the defaultFunction to | |
| 952 | * produce the default value if the conversion fails. | |
| 953 | * | |
| 954 | * @param <K> the key type | |
| 955 | * @param map the map whose value to look up | |
| 956 | * @param key the key of the value to look up in that map | |
| 957 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 958 | * @return the value in the map as a number, or defaultValue produced by the defaultFunction if the original value | |
| 959 | * is null, the map is null or the number conversion fails | |
| 960 | * @since 4.5 | |
| 961 | */ | |
| 962 | public static <K> Number getNumber(final Map<? super K, ?> map, final K key, | |
| 963 | final Function<K, Number> defaultFunction) { | |
| 964 |
1
1. getNumber : replaced return value with null for org/apache/commons/collections4/MapUtils::getNumber → KILLED |
return applyDefaultFunction(map, key, MapUtils::getNumber, defaultFunction); |
| 965 | } | |
| 966 | ||
| 967 | /** | |
| 968 | * Looks up the given key in the given map, converting the result into a number, using the default value if the | |
| 969 | * conversion fails. | |
| 970 | * | |
| 971 | * @param <K> the key type | |
| 972 | * @param map the map whose value to look up | |
| 973 | * @param key the key of the value to look up in that map | |
| 974 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 975 | * @return the value in the map as a number, or defaultValue if the original value is null, the map is null or the | |
| 976 | * number conversion fails | |
| 977 | */ | |
| 978 | public static <K> Number getNumber(final Map<? super K, ?> map, final K key, final Number defaultValue) { | |
| 979 |
1
1. getNumber : replaced return value with null for org/apache/commons/collections4/MapUtils::getNumber → KILLED |
return applyDefaultValue(map, key, MapUtils::getNumber, defaultValue); |
| 980 | } | |
| 981 | ||
| 982 | // ------------------------------------------------------------------------- | |
| 983 | /** | |
| 984 | * Gets from a Map in a null-safe manner. | |
| 985 | * | |
| 986 | * @param <K> the key type | |
| 987 | * @param <V> the value type | |
| 988 | * @param map the map to use | |
| 989 | * @param key the key to look up | |
| 990 | * @return the value in the Map, {@code null} if null map input | |
| 991 | */ | |
| 992 | public static <K, V> V getObject(final Map<? super K, V> map, final K key) { | |
| 993 |
1
1. getObject : negated conditional → KILLED |
if (map != null) { |
| 994 |
1
1. getObject : replaced return value with null for org/apache/commons/collections4/MapUtils::getObject → KILLED |
return map.get(key); |
| 995 | } | |
| 996 | return null; | |
| 997 | } | |
| 998 | ||
| 999 | // ------------------------------------------------------------------------- | |
| 1000 | /** | |
| 1001 | * Looks up the given key in the given map, converting null into the given default value. | |
| 1002 | * | |
| 1003 | * @param <K> the key type | |
| 1004 | * @param <V> the value type | |
| 1005 | * @param map the map whose value to look up | |
| 1006 | * @param key the key of the value to look up in that map | |
| 1007 | * @param defaultValue what to return if the value is null | |
| 1008 | * @return the value in the map, or defaultValue if the original value is null or the map is null | |
| 1009 | */ | |
| 1010 | public static <K, V> V getObject(final Map<K, V> map, final K key, final V defaultValue) { | |
| 1011 |
1
1. getObject : negated conditional → KILLED |
if (map != null) { |
| 1012 | final V answer = map.get(key); | |
| 1013 |
1
1. getObject : negated conditional → KILLED |
if (answer != null) { |
| 1014 |
1
1. getObject : replaced return value with null for org/apache/commons/collections4/MapUtils::getObject → KILLED |
return answer; |
| 1015 | } | |
| 1016 | } | |
| 1017 |
1
1. getObject : replaced return value with null for org/apache/commons/collections4/MapUtils::getObject → KILLED |
return defaultValue; |
| 1018 | } | |
| 1019 | ||
| 1020 | /** | |
| 1021 | * Gets a Short from a Map in a null-safe manner. | |
| 1022 | * <p> | |
| 1023 | * The Short is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 1024 | * </p> | |
| 1025 | * | |
| 1026 | * @param <K> the key type | |
| 1027 | * @param map the map to use | |
| 1028 | * @param key the key to look up | |
| 1029 | * @return the value in the Map as a Short, {@code null} if null map input | |
| 1030 | */ | |
| 1031 | public static <K> Short getShort(final Map<? super K, ?> map, final K key) { | |
| 1032 | final Number answer = getNumber(map, key); | |
| 1033 |
1
1. getShort : negated conditional → KILLED |
if (answer == null) { |
| 1034 |
1
1. getShort : replaced Short return value with 0 for org/apache/commons/collections4/MapUtils::getShort → KILLED |
return null; |
| 1035 | } | |
| 1036 |
1
1. getShort : negated conditional → KILLED |
if (answer instanceof Short) { |
| 1037 |
1
1. getShort : replaced Short return value with 0 for org/apache/commons/collections4/MapUtils::getShort → KILLED |
return (Short) answer; |
| 1038 | } | |
| 1039 |
1
1. getShort : replaced Short return value with 0 for org/apache/commons/collections4/MapUtils::getShort → KILLED |
return Short.valueOf(answer.shortValue()); |
| 1040 | } | |
| 1041 | ||
| 1042 | /** | |
| 1043 | * Looks up the given key in the given map, converting the result into a short, using the defaultFunction to produce | |
| 1044 | * the default value if the conversion fails. | |
| 1045 | * | |
| 1046 | * @param <K> the key type | |
| 1047 | * @param map the map whose value to look up | |
| 1048 | * @param key the key of the value to look up in that map | |
| 1049 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 1050 | * @return the value in the map as a number, or defaultValue produced by the defaultFunction if the original value | |
| 1051 | * is null, the map is null or the number conversion fails | |
| 1052 | * @since 4.5 | |
| 1053 | */ | |
| 1054 | public static <K> Short getShort(final Map<? super K, ?> map, final K key, | |
| 1055 | final Function<K, Short> defaultFunction) { | |
| 1056 |
1
1. getShort : replaced Short return value with 0 for org/apache/commons/collections4/MapUtils::getShort → KILLED |
return applyDefaultFunction(map, key, MapUtils::getShort, defaultFunction); |
| 1057 | } | |
| 1058 | ||
| 1059 | /** | |
| 1060 | * Looks up the given key in the given map, converting the result into a short, using the default value if the | |
| 1061 | * conversion fails. | |
| 1062 | * | |
| 1063 | * @param <K> the key type | |
| 1064 | * @param map the map whose value to look up | |
| 1065 | * @param key the key of the value to look up in that map | |
| 1066 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 1067 | * @return the value in the map as a number, or defaultValue if the original value is null, the map is null or the | |
| 1068 | * number conversion fails | |
| 1069 | */ | |
| 1070 | public static <K> Short getShort(final Map<? super K, ?> map, final K key, final Short defaultValue) { | |
| 1071 |
1
1. getShort : replaced Short return value with 0 for org/apache/commons/collections4/MapUtils::getShort → KILLED |
return applyDefaultValue(map, key, MapUtils::getShort, defaultValue); |
| 1072 | } | |
| 1073 | ||
| 1074 | /** | |
| 1075 | * Gets a short from a Map in a null-safe manner. | |
| 1076 | * <p> | |
| 1077 | * The short is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 1078 | * </p> | |
| 1079 | * | |
| 1080 | * @param <K> the key type | |
| 1081 | * @param map the map to use | |
| 1082 | * @param key the key to look up | |
| 1083 | * @return the value in the Map as a short, {@code 0} if null map input | |
| 1084 | */ | |
| 1085 | public static <K> short getShortValue(final Map<? super K, ?> map, final K key) { | |
| 1086 |
1
1. getShortValue : replaced short return with 0 for org/apache/commons/collections4/MapUtils::getShortValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getShort, 0).shortValue(); |
| 1087 | } | |
| 1088 | ||
| 1089 | /** | |
| 1090 | * Gets a short from a Map in a null-safe manner, using the default value produced by the defaultFunction if the | |
| 1091 | * conversion fails. | |
| 1092 | * <p> | |
| 1093 | * The short is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 1094 | * </p> | |
| 1095 | * | |
| 1096 | * @param <K> the key type | |
| 1097 | * @param map the map to use | |
| 1098 | * @param key the key to look up | |
| 1099 | * @param defaultFunction produce the default value to return if the value is null or if the conversion fails | |
| 1100 | * @return the value in the Map as a short, default value produced by the {@code defaultFunction} if null map | |
| 1101 | * input | |
| 1102 | * @since 4.5 | |
| 1103 | */ | |
| 1104 | public static <K> short getShortValue(final Map<? super K, ?> map, final K key, | |
| 1105 | final Function<K, Short> defaultFunction) { | |
| 1106 |
1
1. getShortValue : replaced short return with 0 for org/apache/commons/collections4/MapUtils::getShortValue → KILLED |
return applyDefaultFunction(map, key, MapUtils::getShort, defaultFunction, (short) 0).shortValue(); |
| 1107 | } | |
| 1108 | ||
| 1109 | /** | |
| 1110 | * Gets a short from a Map in a null-safe manner, using the default value if the conversion fails. | |
| 1111 | * <p> | |
| 1112 | * The short is obtained from the results of {@link #getNumber(Map,Object)}. | |
| 1113 | * </p> | |
| 1114 | * | |
| 1115 | * @param <K> the key type | |
| 1116 | * @param map the map to use | |
| 1117 | * @param key the key to look up | |
| 1118 | * @param defaultValue return if the value is null or if the conversion fails | |
| 1119 | * @return the value in the Map as a short, {@code defaultValue} if null map input | |
| 1120 | */ | |
| 1121 | public static <K> short getShortValue(final Map<? super K, ?> map, final K key, final short defaultValue) { | |
| 1122 |
1
1. getShortValue : replaced short return with 0 for org/apache/commons/collections4/MapUtils::getShortValue → KILLED |
return applyDefaultValue(map, key, MapUtils::getShort, defaultValue).shortValue(); |
| 1123 | } | |
| 1124 | ||
| 1125 | /** | |
| 1126 | * Gets a String from a Map in a null-safe manner. | |
| 1127 | * <p> | |
| 1128 | * The String is obtained via {@code toString}. | |
| 1129 | * </p> | |
| 1130 | * | |
| 1131 | * @param <K> the key type | |
| 1132 | * @param map the map to use | |
| 1133 | * @param key the key to look up | |
| 1134 | * @return the value in the Map as a String, {@code null} if null map input | |
| 1135 | */ | |
| 1136 | public static <K> String getString(final Map<? super K, ?> map, final K key) { | |
| 1137 |
1
1. getString : negated conditional → KILLED |
if (map != null) { |
| 1138 | final Object answer = map.get(key); | |
| 1139 |
1
1. getString : negated conditional → KILLED |
if (answer != null) { |
| 1140 |
1
1. getString : replaced return value with "" for org/apache/commons/collections4/MapUtils::getString → KILLED |
return answer.toString(); |
| 1141 | } | |
| 1142 | } | |
| 1143 |
1
1. getString : replaced return value with "" for org/apache/commons/collections4/MapUtils::getString → KILLED |
return null; |
| 1144 | } | |
| 1145 | ||
| 1146 | /** | |
| 1147 | * Looks up the given key in the given map, converting the result into a string, using the defaultFunction to | |
| 1148 | * produce the default value if the conversion fails. | |
| 1149 | * | |
| 1150 | * @param <K> the key type | |
| 1151 | * @param map the map whose value to look up | |
| 1152 | * @param key the key of the value to look up in that map | |
| 1153 | * @param defaultFunction what to produce the default value if the value is null or if the conversion fails | |
| 1154 | * @return the value in the map as a string, or defaultValue produced by the defaultFunction if the original value | |
| 1155 | * is null, the map is null or the string conversion fails | |
| 1156 | * @since 4.5 | |
| 1157 | */ | |
| 1158 | public static <K> String getString(final Map<? super K, ?> map, final K key, | |
| 1159 | final Function<K, String> defaultFunction) { | |
| 1160 |
1
1. getString : replaced return value with "" for org/apache/commons/collections4/MapUtils::getString → KILLED |
return applyDefaultFunction(map, key, MapUtils::getString, defaultFunction); |
| 1161 | } | |
| 1162 | ||
| 1163 | /** | |
| 1164 | * Looks up the given key in the given map, converting the result into a string, using the default value if the | |
| 1165 | * conversion fails. | |
| 1166 | * | |
| 1167 | * @param <K> the key type | |
| 1168 | * @param map the map whose value to look up | |
| 1169 | * @param key the key of the value to look up in that map | |
| 1170 | * @param defaultValue what to return if the value is null or if the conversion fails | |
| 1171 | * @return the value in the map as a string, or defaultValue if the original value is null, the map is null or the | |
| 1172 | * string conversion fails | |
| 1173 | */ | |
| 1174 | public static <K> String getString(final Map<? super K, ?> map, final K key, final String defaultValue) { | |
| 1175 |
1
1. getString : replaced return value with "" for org/apache/commons/collections4/MapUtils::getString → KILLED |
return applyDefaultValue(map, key, MapUtils::getString, defaultValue); |
| 1176 | } | |
| 1177 | ||
| 1178 | // Misc | |
| 1179 | // ----------------------------------------------------------------------- | |
| 1180 | /** | |
| 1181 | * Inverts the supplied map returning a new HashMap such that the keys of the input are swapped with the values. | |
| 1182 | * <p> | |
| 1183 | * This operation assumes that the inverse mapping is well defined. If the input map had multiple entries with the | |
| 1184 | * same value mapped to different keys, the returned map will map one of those keys to the value, but the exact key | |
| 1185 | * which will be mapped is undefined. | |
| 1186 | * </p> | |
| 1187 | * | |
| 1188 | * @param <K> the key type | |
| 1189 | * @param <V> the value type | |
| 1190 | * @param map the map to invert, may not be null | |
| 1191 | * @return a new HashMap containing the inverted data | |
| 1192 | * @throws NullPointerException if the map is null | |
| 1193 | */ | |
| 1194 | public static <K, V> Map<V, K> invertMap(final Map<K, V> map) { | |
| 1195 | final Map<V, K> out = new HashMap<>(map.size()); | |
| 1196 | for (final Entry<K, V> entry : map.entrySet()) { | |
| 1197 | out.put(entry.getValue(), entry.getKey()); | |
| 1198 | } | |
| 1199 |
1
1. invertMap : replaced return value with null for org/apache/commons/collections4/MapUtils::invertMap → KILLED |
return out; |
| 1200 | } | |
| 1201 | ||
| 1202 | /** | |
| 1203 | * Null-safe check if the specified map is empty. | |
| 1204 | * <p> | |
| 1205 | * Null returns true. | |
| 1206 | * </p> | |
| 1207 | * | |
| 1208 | * @param map the map to check, may be null | |
| 1209 | * @return true if empty or null | |
| 1210 | * @since 3.2 | |
| 1211 | */ | |
| 1212 | public static boolean isEmpty(final Map<?, ?> map) { | |
| 1213 |
3
1. isEmpty : replaced boolean return with true for org/apache/commons/collections4/MapUtils::isEmpty → KILLED 2. isEmpty : negated conditional → KILLED 3. isEmpty : negated conditional → KILLED |
return map == null || map.isEmpty(); |
| 1214 | } | |
| 1215 | ||
| 1216 | /** | |
| 1217 | * Null-safe check if the specified map is not empty. | |
| 1218 | * <p> | |
| 1219 | * Null returns false. | |
| 1220 | * </p> | |
| 1221 | * | |
| 1222 | * @param map the map to check, may be null | |
| 1223 | * @return true if non-null and non-empty | |
| 1224 | * @since 3.2 | |
| 1225 | */ | |
| 1226 | public static boolean isNotEmpty(final Map<?, ?> map) { | |
| 1227 |
2
1. isNotEmpty : replaced boolean return with true for org/apache/commons/collections4/MapUtils::isNotEmpty → KILLED 2. isNotEmpty : negated conditional → KILLED |
return !MapUtils.isEmpty(map); |
| 1228 | } | |
| 1229 | ||
| 1230 | /** | |
| 1231 | * Get the specified {@link Map} as an {@link IterableMap}. | |
| 1232 | * | |
| 1233 | * @param <K> the key type | |
| 1234 | * @param <V> the value type | |
| 1235 | * @param map to wrap if necessary. | |
| 1236 | * @return IterableMap<K, V> | |
| 1237 | * @throws NullPointerException if map is null | |
| 1238 | * @since 4.0 | |
| 1239 | */ | |
| 1240 | public static <K, V> IterableMap<K, V> iterableMap(final Map<K, V> map) { | |
| 1241 | Objects.requireNonNull(map, "map"); | |
| 1242 |
2
1. iterableMap : negated conditional → KILLED 2. iterableMap : replaced return value with null for org/apache/commons/collections4/MapUtils::iterableMap → KILLED |
return map instanceof IterableMap ? (IterableMap<K, V>) map : new AbstractMapDecorator<K, V>(map) { |
| 1243 | // empty | |
| 1244 | }; | |
| 1245 | } | |
| 1246 | ||
| 1247 | /** | |
| 1248 | * Get the specified {@link SortedMap} as an {@link IterableSortedMap}. | |
| 1249 | * | |
| 1250 | * @param <K> the key type | |
| 1251 | * @param <V> the value type | |
| 1252 | * @param sortedMap to wrap if necessary | |
| 1253 | * @return {@link IterableSortedMap}<K, V> | |
| 1254 | * @throws NullPointerException if sortedMap is null | |
| 1255 | * @since 4.0 | |
| 1256 | */ | |
| 1257 | public static <K, V> IterableSortedMap<K, V> iterableSortedMap(final SortedMap<K, V> sortedMap) { | |
| 1258 | Objects.requireNonNull(sortedMap, "sortedMap"); | |
| 1259 |
2
1. iterableSortedMap : negated conditional → KILLED 2. iterableSortedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::iterableSortedMap → KILLED |
return sortedMap instanceof IterableSortedMap ? (IterableSortedMap<K, V>) sortedMap |
| 1260 | : new AbstractSortedMapDecorator<K, V>(sortedMap) { | |
| 1261 | // empty | |
| 1262 | }; | |
| 1263 | } | |
| 1264 | ||
| 1265 | /** | |
| 1266 | * Returns a "lazy" map whose values will be created on demand. | |
| 1267 | * <p> | |
| 1268 | * When the key passed to the returned map's {@link Map#get(Object)} method is not present in the map, then the | |
| 1269 | * factory will be used to create a new object and that object will become the value associated with that key. | |
| 1270 | * </p> | |
| 1271 | * <p> | |
| 1272 | * For instance: | |
| 1273 | * </p> | |
| 1274 | * <pre> | |
| 1275 | * Factory factory = new Factory() { | |
| 1276 | * public Object create() { | |
| 1277 | * return new Date(); | |
| 1278 | * } | |
| 1279 | * } | |
| 1280 | * Map lazyMap = MapUtils.lazyMap(new HashMap(), factory); | |
| 1281 | * Object obj = lazyMap.get("test"); | |
| 1282 | * </pre> | |
| 1283 | * | |
| 1284 | * <p> | |
| 1285 | * After the above code is executed, {@code obj} will contain a new {@code Date} instance. Furthermore, | |
| 1286 | * that {@code Date} instance is the value for the {@code "test"} key in the map. | |
| 1287 | * </p> | |
| 1288 | * | |
| 1289 | * @param <K> the key type | |
| 1290 | * @param <V> the value type | |
| 1291 | * @param map the map to make lazy, must not be null | |
| 1292 | * @param factory the factory for creating new objects, must not be null | |
| 1293 | * @return a lazy map backed by the given map | |
| 1294 | * @throws NullPointerException if the Map or Factory is null | |
| 1295 | */ | |
| 1296 | public static <K, V> IterableMap<K, V> lazyMap(final Map<K, V> map, final Factory<? extends V> factory) { | |
| 1297 |
1
1. lazyMap : replaced return value with null for org/apache/commons/collections4/MapUtils::lazyMap → KILLED |
return LazyMap.lazyMap(map, factory); |
| 1298 | } | |
| 1299 | ||
| 1300 | // ----------------------------------------------------------------------- | |
| 1301 | ||
| 1302 | /** | |
| 1303 | * Returns a "lazy" map whose values will be created on demand. | |
| 1304 | * <p> | |
| 1305 | * When the key passed to the returned map's {@link Map#get(Object)} method is not present in the map, then the | |
| 1306 | * factory will be used to create a new object and that object will become the value associated with that key. The | |
| 1307 | * factory is a {@link Transformer} that will be passed the key which it must transform into the value. | |
| 1308 | * </p> | |
| 1309 | * <p> | |
| 1310 | * For instance: | |
| 1311 | * </p> | |
| 1312 | * <pre> | |
| 1313 | * Transformer factory = new Transformer() { | |
| 1314 | * public Object transform(Object mapKey) { | |
| 1315 | * return new File(mapKey); | |
| 1316 | * } | |
| 1317 | * } | |
| 1318 | * Map lazyMap = MapUtils.lazyMap(new HashMap(), factory); | |
| 1319 | * Object obj = lazyMap.get("C:/dev"); | |
| 1320 | * </pre> | |
| 1321 | * | |
| 1322 | * <p> | |
| 1323 | * After the above code is executed, {@code obj} will contain a new {@code File} instance for the C drive | |
| 1324 | * dev directory. Furthermore, that {@code File} instance is the value for the {@code "C:/dev"} key in the | |
| 1325 | * map. | |
| 1326 | * </p> | |
| 1327 | * <p> | |
| 1328 | * If a lazy map is wrapped by a synchronized map, the result is a simple synchronized cache. When an object is not | |
| 1329 | * is the cache, the cache itself calls back to the factory Transformer to populate itself, all within the same | |
| 1330 | * synchronized block. | |
| 1331 | * </p> | |
| 1332 | * | |
| 1333 | * @param <K> the key type | |
| 1334 | * @param <V> the value type | |
| 1335 | * @param map the map to make lazy, must not be null | |
| 1336 | * @param transformerFactory the factory for creating new objects, must not be null | |
| 1337 | * @return a lazy map backed by the given map | |
| 1338 | * @throws NullPointerException if the Map or Transformer is null | |
| 1339 | */ | |
| 1340 | public static <K, V> IterableMap<K, V> lazyMap(final Map<K, V> map, | |
| 1341 | final Transformer<? super K, ? extends V> transformerFactory) { | |
| 1342 |
1
1. lazyMap : replaced return value with null for org/apache/commons/collections4/MapUtils::lazyMap → KILLED |
return LazyMap.lazyMap(map, transformerFactory); |
| 1343 | } | |
| 1344 | ||
| 1345 | /** | |
| 1346 | * Returns a "lazy" sorted map whose values will be created on demand. | |
| 1347 | * <p> | |
| 1348 | * When the key passed to the returned map's {@link Map#get(Object)} method is not present in the map, then the | |
| 1349 | * factory will be used to create a new object and that object will become the value associated with that key. | |
| 1350 | * </p> | |
| 1351 | * <p> | |
| 1352 | * For instance: | |
| 1353 | * </p> | |
| 1354 | * <pre> | |
| 1355 | * Factory factory = new Factory() { | |
| 1356 | * public Object create() { | |
| 1357 | * return new Date(); | |
| 1358 | * } | |
| 1359 | * } | |
| 1360 | * SortedMap lazy = MapUtils.lazySortedMap(new TreeMap(), factory); | |
| 1361 | * Object obj = lazy.get("test"); | |
| 1362 | * </pre> | |
| 1363 | * <p> | |
| 1364 | * After the above code is executed, {@code obj} will contain a new {@code Date} instance. Furthermore, | |
| 1365 | * that {@code Date} instance is the value for the {@code "test"} key. | |
| 1366 | * </p> | |
| 1367 | * | |
| 1368 | * @param <K> the key type | |
| 1369 | * @param <V> the value type | |
| 1370 | * @param map the map to make lazy, must not be null | |
| 1371 | * @param factory the factory for creating new objects, must not be null | |
| 1372 | * @return a lazy map backed by the given map | |
| 1373 | * @throws NullPointerException if the SortedMap or Factory is null | |
| 1374 | */ | |
| 1375 | public static <K, V> SortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory) { | |
| 1376 |
1
1. lazySortedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::lazySortedMap → NO_COVERAGE |
return LazySortedMap.lazySortedMap(map, factory); |
| 1377 | } | |
| 1378 | ||
| 1379 | /** | |
| 1380 | * Returns a "lazy" sorted map whose values will be created on demand. | |
| 1381 | * <p> | |
| 1382 | * When the key passed to the returned map's {@link Map#get(Object)} method is not present in the map, then the | |
| 1383 | * factory will be used to create a new object and that object will become the value associated with that key. The | |
| 1384 | * factory is a {@link Transformer} that will be passed the key which it must transform into the value. | |
| 1385 | * </p> | |
| 1386 | * <p> | |
| 1387 | * For instance: | |
| 1388 | * </p> | |
| 1389 | * <pre> | |
| 1390 | * Transformer factory = new Transformer() { | |
| 1391 | * public Object transform(Object mapKey) { | |
| 1392 | * return new File(mapKey); | |
| 1393 | * } | |
| 1394 | * } | |
| 1395 | * SortedMap lazy = MapUtils.lazySortedMap(new TreeMap(), factory); | |
| 1396 | * Object obj = lazy.get("C:/dev"); | |
| 1397 | * </pre> | |
| 1398 | * <p> | |
| 1399 | * After the above code is executed, {@code obj} will contain a new {@code File} instance for the C drive | |
| 1400 | * dev directory. Furthermore, that {@code File} instance is the value for the {@code "C:/dev"} key in the | |
| 1401 | * map. | |
| 1402 | * </p> | |
| 1403 | * <p> | |
| 1404 | * If a lazy map is wrapped by a synchronized map, the result is a simple synchronized cache. When an object is not | |
| 1405 | * is the cache, the cache itself calls back to the factory Transformer to populate itself, all within the same | |
| 1406 | * synchronized block. | |
| 1407 | * </p> | |
| 1408 | * | |
| 1409 | * @param <K> the key type | |
| 1410 | * @param <V> the value type | |
| 1411 | * @param map the map to make lazy, must not be null | |
| 1412 | * @param transformerFactory the factory for creating new objects, must not be null | |
| 1413 | * @return a lazy map backed by the given map | |
| 1414 | * @throws NullPointerException if the Map or Transformer is null | |
| 1415 | */ | |
| 1416 | public static <K, V> SortedMap<K, V> lazySortedMap(final SortedMap<K, V> map, | |
| 1417 | final Transformer<? super K, ? extends V> transformerFactory) { | |
| 1418 |
1
1. lazySortedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::lazySortedMap → NO_COVERAGE |
return LazySortedMap.lazySortedMap(map, transformerFactory); |
| 1419 | } | |
| 1420 | ||
| 1421 | /** | |
| 1422 | * Creates a mult-value map backed by the given map which returns collections of type ArrayList. | |
| 1423 | * | |
| 1424 | * @param <K> the key type | |
| 1425 | * @param <V> the value type | |
| 1426 | * @param map the map to decorate | |
| 1427 | * @return a multi-value map backed by the given map which returns ArrayLists of values. | |
| 1428 | * @see MultiValueMap | |
| 1429 | * @since 3.2 | |
| 1430 | * @deprecated since 4.1, use {@link MultiValuedMap} instead | |
| 1431 | */ | |
| 1432 | @Deprecated | |
| 1433 | public static <K, V> MultiValueMap<K, V> multiValueMap(final Map<K, ? super Collection<V>> map) { | |
| 1434 |
1
1. multiValueMap : replaced return value with null for org/apache/commons/collections4/MapUtils::multiValueMap → NO_COVERAGE |
return MultiValueMap.<K, V>multiValueMap(map); |
| 1435 | } | |
| 1436 | ||
| 1437 | /** | |
| 1438 | * Creates a multi-value map backed by the given map which returns collections of the specified type. | |
| 1439 | * | |
| 1440 | * @param <K> the key type | |
| 1441 | * @param <V> the value type | |
| 1442 | * @param <C> the collection class type | |
| 1443 | * @param map the map to decorate | |
| 1444 | * @param collectionClass the type of collections to return from the map (must contain public no-arg constructor and | |
| 1445 | * extend Collection) | |
| 1446 | * @return a multi-value map backed by the given map which returns collections of the specified type | |
| 1447 | * @see MultiValueMap | |
| 1448 | * @since 3.2 | |
| 1449 | * @deprecated since 4.1, use {@link MultiValuedMap} instead | |
| 1450 | */ | |
| 1451 | @Deprecated | |
| 1452 | public static <K, V, C extends Collection<V>> MultiValueMap<K, V> multiValueMap(final Map<K, C> map, | |
| 1453 | final Class<C> collectionClass) { | |
| 1454 |
1
1. multiValueMap : replaced return value with null for org/apache/commons/collections4/MapUtils::multiValueMap → NO_COVERAGE |
return MultiValueMap.multiValueMap(map, collectionClass); |
| 1455 | } | |
| 1456 | ||
| 1457 | /** | |
| 1458 | * Creates a multi-value map backed by the given map which returns collections created by the specified collection | |
| 1459 | * factory. | |
| 1460 | * | |
| 1461 | * @param <K> the key type | |
| 1462 | * @param <V> the value type | |
| 1463 | * @param <C> the collection class type | |
| 1464 | * @param map the map to decorate | |
| 1465 | * @param collectionFactory a factor which creates collection objects | |
| 1466 | * @return a multi-value map backed by the given map which returns collections created by the specified collection | |
| 1467 | * factory | |
| 1468 | * @see MultiValueMap | |
| 1469 | * @since 3.2 | |
| 1470 | * @deprecated since 4.1, use {@link MultiValuedMap} instead | |
| 1471 | */ | |
| 1472 | @Deprecated | |
| 1473 | public static <K, V, C extends Collection<V>> MultiValueMap<K, V> multiValueMap(final Map<K, C> map, | |
| 1474 | final Factory<C> collectionFactory) { | |
| 1475 |
1
1. multiValueMap : replaced return value with null for org/apache/commons/collections4/MapUtils::multiValueMap → NO_COVERAGE |
return MultiValueMap.multiValueMap(map, collectionFactory); |
| 1476 | } | |
| 1477 | ||
| 1478 | /** | |
| 1479 | * Returns a map that maintains the order of keys that are added backed by the given map. | |
| 1480 | * <p> | |
| 1481 | * If a key is added twice, the order is determined by the first add. The order is observed through the keySet, | |
| 1482 | * values and entrySet. | |
| 1483 | * </p> | |
| 1484 | * | |
| 1485 | * @param <K> the key type | |
| 1486 | * @param <V> the value type | |
| 1487 | * @param map the map to order, must not be null | |
| 1488 | * @return an ordered map backed by the given map | |
| 1489 | * @throws NullPointerException if the Map is null | |
| 1490 | */ | |
| 1491 | public static <K, V> OrderedMap<K, V> orderedMap(final Map<K, V> map) { | |
| 1492 |
1
1. orderedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::orderedMap → KILLED |
return ListOrderedMap.listOrderedMap(map); |
| 1493 | } | |
| 1494 | ||
| 1495 | /** | |
| 1496 | * Populates a Map using the supplied {@code Transformer}s to transform the elements into keys and values. | |
| 1497 | * | |
| 1498 | * @param <K> the key type | |
| 1499 | * @param <V> the value type | |
| 1500 | * @param <E> the type of object contained in the {@link Iterable} | |
| 1501 | * @param map the {@code Map} to populate. | |
| 1502 | * @param elements the {@code Iterable} containing the input values for the map. | |
| 1503 | * @param keyTransformer the {@code Transformer} used to transform the element into a key value | |
| 1504 | * @param valueTransformer the {@code Transformer} used to transform the element into a value | |
| 1505 | * @throws NullPointerException if the map, elements or transformers are null | |
| 1506 | */ | |
| 1507 | public static <K, V, E> void populateMap(final Map<K, V> map, final Iterable<? extends E> elements, | |
| 1508 | final Transformer<E, K> keyTransformer, final Transformer<E, V> valueTransformer) { | |
| 1509 | final Iterator<? extends E> iter = elements.iterator(); | |
| 1510 |
1
1. populateMap : negated conditional → KILLED |
while (iter.hasNext()) { |
| 1511 | final E temp = iter.next(); | |
| 1512 | map.put(keyTransformer.transform(temp), valueTransformer.transform(temp)); | |
| 1513 | } | |
| 1514 | } | |
| 1515 | ||
| 1516 | /** | |
| 1517 | * Populates a Map using the supplied {@code Transformer} to transform the elements into keys, using the | |
| 1518 | * unaltered element as the value in the {@code Map}. | |
| 1519 | * | |
| 1520 | * @param <K> the key type | |
| 1521 | * @param <V> the value type | |
| 1522 | * @param map the {@code Map} to populate. | |
| 1523 | * @param elements the {@code Iterable} containing the input values for the map. | |
| 1524 | * @param keyTransformer the {@code Transformer} used to transform the element into a key value | |
| 1525 | * @throws NullPointerException if the map, elements or transformer are null | |
| 1526 | */ | |
| 1527 | public static <K, V> void populateMap(final Map<K, V> map, final Iterable<? extends V> elements, | |
| 1528 | final Transformer<V, K> keyTransformer) { | |
| 1529 |
1
1. populateMap : removed call to org/apache/commons/collections4/MapUtils::populateMap → KILLED |
populateMap(map, elements, keyTransformer, TransformerUtils.<V>nopTransformer()); |
| 1530 | } | |
| 1531 | ||
| 1532 | /** | |
| 1533 | * Populates a MultiMap using the supplied {@code Transformer}s to transform the elements into keys and values. | |
| 1534 | * | |
| 1535 | * @param <K> the key type | |
| 1536 | * @param <V> the value type | |
| 1537 | * @param <E> the type of object contained in the {@link Iterable} | |
| 1538 | * @param map the {@code MultiMap} to populate. | |
| 1539 | * @param elements the {@code Iterable} containing the input values for the map. | |
| 1540 | * @param keyTransformer the {@code Transformer} used to transform the element into a key value | |
| 1541 | * @param valueTransformer the {@code Transformer} used to transform the element into a value | |
| 1542 | * @throws NullPointerException if the map, collection or transformers are null | |
| 1543 | */ | |
| 1544 | public static <K, V, E> void populateMap(final MultiMap<K, V> map, final Iterable<? extends E> elements, | |
| 1545 | final Transformer<E, K> keyTransformer, final Transformer<E, V> valueTransformer) { | |
| 1546 | final Iterator<? extends E> iter = elements.iterator(); | |
| 1547 |
1
1. populateMap : negated conditional → KILLED |
while (iter.hasNext()) { |
| 1548 | final E temp = iter.next(); | |
| 1549 | map.put(keyTransformer.transform(temp), valueTransformer.transform(temp)); | |
| 1550 | } | |
| 1551 | } | |
| 1552 | ||
| 1553 | /** | |
| 1554 | * Populates a MultiMap using the supplied {@code Transformer} to transform the elements into keys, using the | |
| 1555 | * unaltered element as the value in the {@code MultiMap}. | |
| 1556 | * | |
| 1557 | * @param <K> the key type | |
| 1558 | * @param <V> the value type | |
| 1559 | * @param map the {@code MultiMap} to populate. | |
| 1560 | * @param elements the {@code Iterable} to use as input values for the map. | |
| 1561 | * @param keyTransformer the {@code Transformer} used to transform the element into a key value | |
| 1562 | * @throws NullPointerException if the map, elements or transformer are null | |
| 1563 | */ | |
| 1564 | public static <K, V> void populateMap(final MultiMap<K, V> map, final Iterable<? extends V> elements, | |
| 1565 | final Transformer<V, K> keyTransformer) { | |
| 1566 |
1
1. populateMap : removed call to org/apache/commons/collections4/MapUtils::populateMap → NO_COVERAGE |
populateMap(map, elements, keyTransformer, TransformerUtils.<V>nopTransformer()); |
| 1567 | } | |
| 1568 | ||
| 1569 | /** | |
| 1570 | * Returns a predicated (validating) map backed by the given map. | |
| 1571 | * <p> | |
| 1572 | * Only objects that pass the tests in the given predicates can be added to the map. Trying to add an invalid object | |
| 1573 | * results in an IllegalArgumentException. Keys must pass the key predicate, values must pass the value predicate. | |
| 1574 | * It is important not to use the original map after invoking this method, as it is a backdoor for adding invalid | |
| 1575 | * objects. | |
| 1576 | * </p> | |
| 1577 | * | |
| 1578 | * @param <K> the key type | |
| 1579 | * @param <V> the value type | |
| 1580 | * @param map the map to predicate, must not be null | |
| 1581 | * @param keyPred the predicate for keys, null means no check | |
| 1582 | * @param valuePred the predicate for values, null means no check | |
| 1583 | * @return a predicated map backed by the given map | |
| 1584 | * @throws NullPointerException if the Map is null | |
| 1585 | */ | |
| 1586 | public static <K, V> IterableMap<K, V> predicatedMap(final Map<K, V> map, final Predicate<? super K> keyPred, | |
| 1587 | final Predicate<? super V> valuePred) { | |
| 1588 |
1
1. predicatedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::predicatedMap → KILLED |
return PredicatedMap.predicatedMap(map, keyPred, valuePred); |
| 1589 | } | |
| 1590 | ||
| 1591 | /** | |
| 1592 | * Returns a predicated (validating) sorted map backed by the given map. | |
| 1593 | * <p> | |
| 1594 | * Only objects that pass the tests in the given predicates can be added to the map. Trying to add an invalid object | |
| 1595 | * results in an IllegalArgumentException. Keys must pass the key predicate, values must pass the value predicate. | |
| 1596 | * It is important not to use the original map after invoking this method, as it is a backdoor for adding invalid | |
| 1597 | * objects. | |
| 1598 | * </p> | |
| 1599 | * | |
| 1600 | * @param <K> the key type | |
| 1601 | * @param <V> the value type | |
| 1602 | * @param map the map to predicate, must not be null | |
| 1603 | * @param keyPred the predicate for keys, null means no check | |
| 1604 | * @param valuePred the predicate for values, null means no check | |
| 1605 | * @return a predicated map backed by the given map | |
| 1606 | * @throws NullPointerException if the SortedMap is null | |
| 1607 | */ | |
| 1608 | public static <K, V> SortedMap<K, V> predicatedSortedMap(final SortedMap<K, V> map, | |
| 1609 | final Predicate<? super K> keyPred, final Predicate<? super V> valuePred) { | |
| 1610 |
1
1. predicatedSortedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::predicatedSortedMap → NO_COVERAGE |
return PredicatedSortedMap.predicatedSortedMap(map, keyPred, valuePred); |
| 1611 | } | |
| 1612 | ||
| 1613 | /** | |
| 1614 | * Writes indentation to the given stream. | |
| 1615 | * | |
| 1616 | * @param out the stream to indent | |
| 1617 | */ | |
| 1618 | private static void printIndent(final PrintStream out, final int indent) { | |
| 1619 |
3
1. printIndent : Changed increment from 1 to -1 → TIMED_OUT 2. printIndent : negated conditional → TIMED_OUT 3. printIndent : changed conditional boundary → KILLED |
for (int i = 0; i < indent; i++) { |
| 1620 |
1
1. printIndent : removed call to java/io/PrintStream::print → KILLED |
out.print(INDENT_STRING); |
| 1621 | } | |
| 1622 | } | |
| 1623 | ||
| 1624 | // ----------------------------------------------------------------------- | |
| 1625 | /** | |
| 1626 | * Puts all the keys and values from the specified array into the map. | |
| 1627 | * <p> | |
| 1628 | * This method is an alternative to the {@link java.util.Map#putAll(java.util.Map)} method and constructors. It | |
| 1629 | * allows you to build a map from an object array of various possible styles. | |
| 1630 | * </p> | |
| 1631 | * <p> | |
| 1632 | * If the first entry in the object array implements {@link java.util.Map.Entry} or {@link KeyValue} then the key | |
| 1633 | * and value are added from that object. If the first entry in the object array is an object array itself, then it | |
| 1634 | * is assumed that index 0 in the sub-array is the key and index 1 is the value. Otherwise, the array is treated as | |
| 1635 | * keys and values in alternate indices. | |
| 1636 | * </p> | |
| 1637 | * <p> | |
| 1638 | * For example, to create a color map: | |
| 1639 | * </p> | |
| 1640 | * | |
| 1641 | * <pre> | |
| 1642 | * Map colorMap = MapUtils.putAll(new HashMap(), | |
| 1643 | * new String[][] { { "RED", "#FF0000" }, { "GREEN", "#00FF00" }, { "BLUE", "#0000FF" } }); | |
| 1644 | * </pre> | |
| 1645 | * | |
| 1646 | * <p> | |
| 1647 | * or: | |
| 1648 | * </p> | |
| 1649 | * | |
| 1650 | * <pre> | |
| 1651 | * Map colorMap = MapUtils.putAll(new HashMap(), | |
| 1652 | * new String[] { "RED", "#FF0000", "GREEN", "#00FF00", "BLUE", "#0000FF" }); | |
| 1653 | * </pre> | |
| 1654 | * | |
| 1655 | * <p> | |
| 1656 | * or: | |
| 1657 | * </p> | |
| 1658 | * | |
| 1659 | * <pre> | |
| 1660 | * Map colorMap = MapUtils.putAll(new HashMap(), new Map.Entry[] { new DefaultMapEntry("RED", "#FF0000"), | |
| 1661 | * new DefaultMapEntry("GREEN", "#00FF00"), new DefaultMapEntry("BLUE", "#0000FF") }); | |
| 1662 | * </pre> | |
| 1663 | * | |
| 1664 | * @param <K> the key type | |
| 1665 | * @param <V> the value type | |
| 1666 | * @param map the map to populate, must not be null | |
| 1667 | * @param array an array to populate from, null ignored | |
| 1668 | * @return the input map | |
| 1669 | * @throws NullPointerException if map is null | |
| 1670 | * @throws IllegalArgumentException if sub-array or entry matching used and an entry is invalid | |
| 1671 | * @throws ClassCastException if the array contents is mixed | |
| 1672 | * @since 3.2 | |
| 1673 | */ | |
| 1674 | @SuppressWarnings("unchecked") // As per Javadoc throws CCE for invalid array contents | |
| 1675 | public static <K, V> Map<K, V> putAll(final Map<K, V> map, final Object[] array) { | |
| 1676 | Objects.requireNonNull(map, "map"); | |
| 1677 |
2
1. putAll : negated conditional → KILLED 2. putAll : negated conditional → KILLED |
if (array == null || array.length == 0) { |
| 1678 |
1
1. putAll : replaced return value with null for org/apache/commons/collections4/MapUtils::putAll → KILLED |
return map; |
| 1679 | } | |
| 1680 | final Object obj = array[0]; | |
| 1681 |
1
1. putAll : negated conditional → KILLED |
if (obj instanceof Map.Entry) { |
| 1682 | for (final Object element : array) { | |
| 1683 | // cast ok here, type is checked above | |
| 1684 | final Map.Entry<K, V> entry = (Map.Entry<K, V>) element; | |
| 1685 | map.put(entry.getKey(), entry.getValue()); | |
| 1686 | } | |
| 1687 |
1
1. putAll : negated conditional → KILLED |
} else if (obj instanceof KeyValue) { |
| 1688 | for (final Object element : array) { | |
| 1689 | // cast ok here, type is checked above | |
| 1690 | final KeyValue<K, V> keyval = (KeyValue<K, V>) element; | |
| 1691 | map.put(keyval.getKey(), keyval.getValue()); | |
| 1692 | } | |
| 1693 |
1
1. putAll : negated conditional → KILLED |
} else if (obj instanceof Object[]) { |
| 1694 |
2
1. putAll : changed conditional boundary → KILLED 2. putAll : negated conditional → KILLED |
for (int i = 0; i < array.length; i++) { |
| 1695 | final Object[] sub = (Object[]) array[i]; | |
| 1696 |
3
1. putAll : changed conditional boundary → KILLED 2. putAll : negated conditional → KILLED 3. putAll : negated conditional → KILLED |
if (sub == null || sub.length < 2) { |
| 1697 | throw new IllegalArgumentException("Invalid array element: " + i); | |
| 1698 | } | |
| 1699 | // these casts can fail if array has incorrect types | |
| 1700 | map.put((K) sub[0], (V) sub[1]); | |
| 1701 | } | |
| 1702 | } else { | |
| 1703 |
3
1. putAll : changed conditional boundary → KILLED 2. putAll : Replaced integer subtraction with addition → KILLED 3. putAll : negated conditional → KILLED |
for (int i = 0; i < array.length - 1;) { |
| 1704 | // these casts can fail if array has incorrect types | |
| 1705 |
2
1. putAll : Changed increment from 1 to -1 → TIMED_OUT 2. putAll : Changed increment from 1 to -1 → KILLED |
map.put((K) array[i++], (V) array[i++]); |
| 1706 | } | |
| 1707 | } | |
| 1708 |
1
1. putAll : replaced return value with null for org/apache/commons/collections4/MapUtils::putAll → KILLED |
return map; |
| 1709 | } | |
| 1710 | ||
| 1711 | /** | |
| 1712 | * Protects against adding null values to a map. | |
| 1713 | * <p> | |
| 1714 | * This method checks the value being added to the map, and if it is null it is replaced by an empty string. | |
| 1715 | * </p> | |
| 1716 | * <p> | |
| 1717 | * This could be useful if the map does not accept null values, or for receiving data from a source that may provide | |
| 1718 | * null or empty string which should be held in the same way in the map. | |
| 1719 | * </p> | |
| 1720 | * <p> | |
| 1721 | * Keys are not validated. Note that this method can be used to circumvent the map's value type at runtime. | |
| 1722 | * </p> | |
| 1723 | * | |
| 1724 | * @param <K> the key type | |
| 1725 | * @param map the map to add to, may not be null | |
| 1726 | * @param key the key | |
| 1727 | * @param value the value, null converted to "" | |
| 1728 | * @throws NullPointerException if the map is null | |
| 1729 | */ | |
| 1730 | public static <K> void safeAddToMap(final Map<? super K, Object> map, final K key, final Object value) | |
| 1731 | throws NullPointerException { | |
| 1732 |
1
1. safeAddToMap : negated conditional → KILLED |
map.put(key, value == null ? "" : value); |
| 1733 | } | |
| 1734 | ||
| 1735 | /** | |
| 1736 | * Gets the given map size or 0 if the map is null | |
| 1737 | * | |
| 1738 | * @param map a Map or null | |
| 1739 | * @return the given map size or 0 if the map is null | |
| 1740 | */ | |
| 1741 | public static int size(final Map<?, ?> map) { | |
| 1742 |
2
1. size : negated conditional → KILLED 2. size : replaced int return with 0 for org/apache/commons/collections4/MapUtils::size → KILLED |
return map == null ? 0 : map.size(); |
| 1743 | } | |
| 1744 | ||
| 1745 | // ----------------------------------------------------------------------- | |
| 1746 | /** | |
| 1747 | * Returns a synchronized map backed by the given map. | |
| 1748 | * <p> | |
| 1749 | * You must manually synchronize on the returned buffer's iterator to avoid non-deterministic behavior: | |
| 1750 | * </p> | |
| 1751 | * | |
| 1752 | * <pre> | |
| 1753 | * Map m = MapUtils.synchronizedMap(myMap); | |
| 1754 | * Set s = m.keySet(); // outside synchronized block | |
| 1755 | * synchronized (m) { // synchronized on MAP! | |
| 1756 | * Iterator i = s.iterator(); | |
| 1757 | * while (i.hasNext()) { | |
| 1758 | * process(i.next()); | |
| 1759 | * } | |
| 1760 | * } | |
| 1761 | * </pre> | |
| 1762 | * | |
| 1763 | * <p> | |
| 1764 | * This method uses the implementation in {@link java.util.Collections Collections}. | |
| 1765 | * </p> | |
| 1766 | * | |
| 1767 | * @param <K> the key type | |
| 1768 | * @param <V> the value type | |
| 1769 | * @param map the map to synchronize, must not be null | |
| 1770 | * @return a synchronized map backed by the given map | |
| 1771 | */ | |
| 1772 | public static <K, V> Map<K, V> synchronizedMap(final Map<K, V> map) { | |
| 1773 |
1
1. synchronizedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::synchronizedMap → NO_COVERAGE |
return Collections.synchronizedMap(map); |
| 1774 | } | |
| 1775 | ||
| 1776 | // ----------------------------------------------------------------------- | |
| 1777 | /** | |
| 1778 | * Returns a synchronized sorted map backed by the given sorted map. | |
| 1779 | * <p> | |
| 1780 | * You must manually synchronize on the returned buffer's iterator to avoid non-deterministic behavior: | |
| 1781 | * </p> | |
| 1782 | * | |
| 1783 | * <pre> | |
| 1784 | * Map m = MapUtils.synchronizedSortedMap(myMap); | |
| 1785 | * Set s = m.keySet(); // outside synchronized block | |
| 1786 | * synchronized (m) { // synchronized on MAP! | |
| 1787 | * Iterator i = s.iterator(); | |
| 1788 | * while (i.hasNext()) { | |
| 1789 | * process(i.next()); | |
| 1790 | * } | |
| 1791 | * } | |
| 1792 | * </pre> | |
| 1793 | * | |
| 1794 | * <p> | |
| 1795 | * This method uses the implementation in {@link java.util.Collections Collections}. | |
| 1796 | * </p> | |
| 1797 | * | |
| 1798 | * @param <K> the key type | |
| 1799 | * @param <V> the value type | |
| 1800 | * @param map the map to synchronize, must not be null | |
| 1801 | * @return a synchronized map backed by the given map | |
| 1802 | * @throws NullPointerException if the map is null | |
| 1803 | */ | |
| 1804 | public static <K, V> SortedMap<K, V> synchronizedSortedMap(final SortedMap<K, V> map) { | |
| 1805 |
1
1. synchronizedSortedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::synchronizedSortedMap → NO_COVERAGE |
return Collections.synchronizedSortedMap(map); |
| 1806 | } | |
| 1807 | ||
| 1808 | /** | |
| 1809 | * Creates a new HashMap using data copied from a ResourceBundle. | |
| 1810 | * | |
| 1811 | * @param resourceBundle the resource bundle to convert, may not be null | |
| 1812 | * @return the hashmap containing the data | |
| 1813 | * @throws NullPointerException if the bundle is null | |
| 1814 | */ | |
| 1815 | public static Map<String, Object> toMap(final ResourceBundle resourceBundle) { | |
| 1816 | final Enumeration<String> enumeration = resourceBundle.getKeys(); | |
| 1817 | final Map<String, Object> map = new HashMap<>(); | |
| 1818 | ||
| 1819 |
1
1. toMap : negated conditional → KILLED |
while (enumeration.hasMoreElements()) { |
| 1820 | final String key = enumeration.nextElement(); | |
| 1821 | final Object value = resourceBundle.getObject(key); | |
| 1822 | map.put(key, value); | |
| 1823 | } | |
| 1824 | ||
| 1825 |
1
1. toMap : replaced return value with null for org/apache/commons/collections4/MapUtils::toMap → KILLED |
return map; |
| 1826 | } | |
| 1827 | ||
| 1828 | // ------------------------------------------------------------------------- | |
| 1829 | /** | |
| 1830 | * Gets a new Properties object initialised with the values from a Map. A null input will return an empty properties | |
| 1831 | * object. | |
| 1832 | * <p> | |
| 1833 | * A Properties object may only store non-null keys and values, thus if the provided map contains either a key or | |
| 1834 | * value which is {@code null}, a {@link NullPointerException} will be thrown. | |
| 1835 | * </p> | |
| 1836 | * | |
| 1837 | * @param <K> the key type | |
| 1838 | * @param <V> the value type | |
| 1839 | * @param map the map to convert to a Properties object | |
| 1840 | * @return the properties object | |
| 1841 | * @throws NullPointerException if a key or value in the provided map is {@code null} | |
| 1842 | */ | |
| 1843 | public static <K, V> Properties toProperties(final Map<K, V> map) { | |
| 1844 | final Properties answer = new Properties(); | |
| 1845 |
1
1. toProperties : negated conditional → KILLED |
if (map != null) { |
| 1846 | for (final Entry<K, V> entry2 : map.entrySet()) { | |
| 1847 | final Map.Entry<?, ?> entry = entry2; | |
| 1848 | final Object key = entry.getKey(); | |
| 1849 | final Object value = entry.getValue(); | |
| 1850 | answer.put(key, value); | |
| 1851 | } | |
| 1852 | } | |
| 1853 |
1
1. toProperties : replaced return value with null for org/apache/commons/collections4/MapUtils::toProperties → KILLED |
return answer; |
| 1854 | } | |
| 1855 | ||
| 1856 | /** | |
| 1857 | * Returns a transformed map backed by the given map. | |
| 1858 | * <p> | |
| 1859 | * This method returns a new map (decorating the specified map) that will transform any new entries added to it. | |
| 1860 | * Existing entries in the specified map will not be transformed. If you want that behaviour, see | |
| 1861 | * {@link TransformedMap#transformedMap}. | |
| 1862 | * </p> | |
| 1863 | * <p> | |
| 1864 | * Each object is passed through the transformers as it is added to the Map. It is important not to use the original | |
| 1865 | * map after invoking this method, as it is a backdoor for adding untransformed objects. | |
| 1866 | * </p> | |
| 1867 | * <p> | |
| 1868 | * If there are any elements already in the map being decorated, they are NOT transformed. | |
| 1869 | * </p> | |
| 1870 | * | |
| 1871 | * @param <K> the key type | |
| 1872 | * @param <V> the value type | |
| 1873 | * @param map the map to transform, must not be null, typically empty | |
| 1874 | * @param keyTransformer the transformer for the map keys, null means no transformation | |
| 1875 | * @param valueTransformer the transformer for the map values, null means no transformation | |
| 1876 | * @return a transformed map backed by the given map | |
| 1877 | * @throws NullPointerException if the Map is null | |
| 1878 | */ | |
| 1879 | public static <K, V> IterableMap<K, V> transformedMap(final Map<K, V> map, | |
| 1880 | final Transformer<? super K, ? extends K> keyTransformer, | |
| 1881 | final Transformer<? super V, ? extends V> valueTransformer) { | |
| 1882 |
1
1. transformedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::transformedMap → NO_COVERAGE |
return TransformedMap.transformingMap(map, keyTransformer, valueTransformer); |
| 1883 | } | |
| 1884 | ||
| 1885 | /** | |
| 1886 | * Returns a transformed sorted map backed by the given map. | |
| 1887 | * <p> | |
| 1888 | * This method returns a new sorted map (decorating the specified map) that will transform any new entries added to | |
| 1889 | * it. Existing entries in the specified map will not be transformed. If you want that behaviour, see | |
| 1890 | * {@link TransformedSortedMap#transformedSortedMap}. | |
| 1891 | * </p> | |
| 1892 | * <p> | |
| 1893 | * Each object is passed through the transformers as it is added to the Map. It is important not to use the original | |
| 1894 | * map after invoking this method, as it is a backdoor for adding untransformed objects. | |
| 1895 | * </p> | |
| 1896 | * <p> | |
| 1897 | * If there are any elements already in the map being decorated, they are NOT transformed. | |
| 1898 | * </p> | |
| 1899 | * | |
| 1900 | * @param <K> the key type | |
| 1901 | * @param <V> the value type | |
| 1902 | * @param map the map to transform, must not be null, typically empty | |
| 1903 | * @param keyTransformer the transformer for the map keys, null means no transformation | |
| 1904 | * @param valueTransformer the transformer for the map values, null means no transformation | |
| 1905 | * @return a transformed map backed by the given map | |
| 1906 | * @throws NullPointerException if the SortedMap is null | |
| 1907 | */ | |
| 1908 | public static <K, V> SortedMap<K, V> transformedSortedMap(final SortedMap<K, V> map, | |
| 1909 | final Transformer<? super K, ? extends K> keyTransformer, | |
| 1910 | final Transformer<? super V, ? extends V> valueTransformer) { | |
| 1911 |
1
1. transformedSortedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::transformedSortedMap → NO_COVERAGE |
return TransformedSortedMap.transformingSortedMap(map, keyTransformer, valueTransformer); |
| 1912 | } | |
| 1913 | ||
| 1914 | /** | |
| 1915 | * Returns an unmodifiable map backed by the given map. | |
| 1916 | * <p> | |
| 1917 | * This method uses the implementation in the decorators subpackage. | |
| 1918 | * </p> | |
| 1919 | * | |
| 1920 | * @param <K> the key type | |
| 1921 | * @param <V> the value type | |
| 1922 | * @param map the map to make unmodifiable, must not be null | |
| 1923 | * @return an unmodifiable map backed by the given map | |
| 1924 | * @throws NullPointerException if the map is null | |
| 1925 | */ | |
| 1926 | public static <K, V> Map<K, V> unmodifiableMap(final Map<? extends K, ? extends V> map) { | |
| 1927 |
1
1. unmodifiableMap : replaced return value with null for org/apache/commons/collections4/MapUtils::unmodifiableMap → NO_COVERAGE |
return UnmodifiableMap.unmodifiableMap(map); |
| 1928 | } | |
| 1929 | ||
| 1930 | /** | |
| 1931 | * Returns an unmodifiable sorted map backed by the given sorted map. | |
| 1932 | * <p> | |
| 1933 | * This method uses the implementation in the decorators subpackage. | |
| 1934 | * </p> | |
| 1935 | * | |
| 1936 | * @param <K> the key type | |
| 1937 | * @param <V> the value type | |
| 1938 | * @param map the sorted map to make unmodifiable, must not be null | |
| 1939 | * @return an unmodifiable map backed by the given map | |
| 1940 | * @throws NullPointerException if the map is null | |
| 1941 | */ | |
| 1942 | public static <K, V> SortedMap<K, V> unmodifiableSortedMap(final SortedMap<K, ? extends V> map) { | |
| 1943 |
1
1. unmodifiableSortedMap : replaced return value with null for org/apache/commons/collections4/MapUtils::unmodifiableSortedMap → NO_COVERAGE |
return UnmodifiableSortedMap.unmodifiableSortedMap(map); |
| 1944 | } | |
| 1945 | ||
| 1946 | // Printing methods | |
| 1947 | // ------------------------------------------------------------------------- | |
| 1948 | /** | |
| 1949 | * Prints the given map with nice line breaks. | |
| 1950 | * <p> | |
| 1951 | * This method prints a nicely formatted String describing the Map. Each map entry will be printed with key and | |
| 1952 | * value. When the value is a Map, recursive behaviour occurs. | |
| 1953 | * </p> | |
| 1954 | * <p> | |
| 1955 | * This method is NOT thread-safe in any special way. You must manually synchronize on either this class or the | |
| 1956 | * stream as required. | |
| 1957 | * </p> | |
| 1958 | * | |
| 1959 | * @param out the stream to print to, must not be null | |
| 1960 | * @param label The label to be used, may be {@code null}. If {@code null}, the label is not output. It | |
| 1961 | * typically represents the name of the property in a bean or similar. | |
| 1962 | * @param map The map to print, may be {@code null}. If {@code null}, the text 'null' is output. | |
| 1963 | * @throws NullPointerException if the stream is {@code null} | |
| 1964 | */ | |
| 1965 | public static void verbosePrint(final PrintStream out, final Object label, final Map<?, ?> map) { | |
| 1966 |
1
1. verbosePrint : removed call to org/apache/commons/collections4/MapUtils::verbosePrintInternal → KILLED |
verbosePrintInternal(out, label, map, new ArrayDeque<Map<?, ?>>(), false); |
| 1967 | } | |
| 1968 | ||
| 1969 | /** | |
| 1970 | * Implementation providing functionality for {@link #debugPrint} and for {@link #verbosePrint}. This prints the | |
| 1971 | * given map with nice line breaks. If the debug flag is true, it additionally prints the type of the object value. | |
| 1972 | * If the contents of a map include the map itself, then the text <em>(this Map)</em> is printed out. If the | |
| 1973 | * contents include a parent container of the map, the text <em>(ancestor[i] Map)</em> is printed, where i actually | |
| 1974 | * indicates the number of levels which must be traversed in the sequential list of ancestors (e.g. father, | |
| 1975 | * grandfather, great-grandfather, etc). | |
| 1976 | * | |
| 1977 | * @param out the stream to print to | |
| 1978 | * @param label the label to be used, may be {@code null}. If {@code null}, the label is not output. It | |
| 1979 | * typically represents the name of the property in a bean or similar. | |
| 1980 | * @param map the map to print, may be {@code null}. If {@code null}, the text 'null' is output | |
| 1981 | * @param lineage a stack consisting of any maps in which the previous argument is contained. This is checked to | |
| 1982 | * avoid infinite recursion when printing the output | |
| 1983 | * @param debug flag indicating whether type names should be output. | |
| 1984 | * @throws NullPointerException if the stream is {@code null} | |
| 1985 | */ | |
| 1986 | private static void verbosePrintInternal(final PrintStream out, final Object label, final Map<?, ?> map, | |
| 1987 | final Deque<Map<?, ?>> lineage, final boolean debug) { | |
| 1988 |
1
1. verbosePrintInternal : removed call to org/apache/commons/collections4/MapUtils::printIndent → KILLED |
printIndent(out, lineage.size()); |
| 1989 | ||
| 1990 |
1
1. verbosePrintInternal : negated conditional → KILLED |
if (map == null) { |
| 1991 |
1
1. verbosePrintInternal : negated conditional → KILLED |
if (label != null) { |
| 1992 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::print → KILLED |
out.print(label); |
| 1993 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::print → KILLED |
out.print(" = "); |
| 1994 | } | |
| 1995 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::println → KILLED |
out.println("null"); |
| 1996 | return; | |
| 1997 | } | |
| 1998 |
1
1. verbosePrintInternal : negated conditional → KILLED |
if (label != null) { |
| 1999 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::print → KILLED |
out.print(label); |
| 2000 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::println → KILLED |
out.println(" = "); |
| 2001 | } | |
| 2002 | ||
| 2003 |
1
1. verbosePrintInternal : removed call to org/apache/commons/collections4/MapUtils::printIndent → KILLED |
printIndent(out, lineage.size()); |
| 2004 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::println → KILLED |
out.println("{"); |
| 2005 | ||
| 2006 |
1
1. verbosePrintInternal : removed call to java/util/Deque::addLast → KILLED |
lineage.addLast(map); |
| 2007 | ||
| 2008 | for (final Map.Entry<?, ?> entry : map.entrySet()) { | |
| 2009 | final Object childKey = entry.getKey(); | |
| 2010 | final Object childValue = entry.getValue(); | |
| 2011 |
2
1. verbosePrintInternal : negated conditional → TIMED_OUT 2. verbosePrintInternal : negated conditional → KILLED |
if (childValue instanceof Map && !lineage.contains(childValue)) { |
| 2012 |
2
1. verbosePrintInternal : negated conditional → KILLED 2. verbosePrintInternal : removed call to org/apache/commons/collections4/MapUtils::verbosePrintInternal → KILLED |
verbosePrintInternal(out, childKey == null ? "null" : childKey, (Map<?, ?>) childValue, lineage, debug); |
| 2013 | } else { | |
| 2014 |
1
1. verbosePrintInternal : removed call to org/apache/commons/collections4/MapUtils::printIndent → KILLED |
printIndent(out, lineage.size()); |
| 2015 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::print → KILLED |
out.print(childKey); |
| 2016 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::print → KILLED |
out.print(" = "); |
| 2017 | ||
| 2018 | final int lineageIndex = IterableUtils.indexOf(lineage, PredicateUtils.equalPredicate(childValue)); | |
| 2019 |
1
1. verbosePrintInternal : negated conditional → KILLED |
if (lineageIndex == -1) { |
| 2020 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::print → KILLED |
out.print(childValue); |
| 2021 |
2
1. verbosePrintInternal : Replaced integer subtraction with addition → KILLED 2. verbosePrintInternal : negated conditional → KILLED |
} else if (lineage.size() - 1 == lineageIndex) { |
| 2022 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::print → KILLED |
out.print("(this Map)"); |
| 2023 | } else { | |
| 2024 |
4
1. verbosePrintInternal : Replaced integer subtraction with addition → KILLED 2. verbosePrintInternal : Replaced integer subtraction with addition → KILLED 3. verbosePrintInternal : Replaced integer subtraction with addition → KILLED 4. verbosePrintInternal : removed call to java/io/PrintStream::print → KILLED |
out.print("(ancestor[" + (lineage.size() - 1 - lineageIndex - 1) + "] Map)"); |
| 2025 | } | |
| 2026 | ||
| 2027 |
2
1. verbosePrintInternal : negated conditional → KILLED 2. verbosePrintInternal : negated conditional → KILLED |
if (debug && childValue != null) { |
| 2028 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::print → KILLED |
out.print(' '); |
| 2029 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::println → KILLED |
out.println(childValue.getClass().getName()); |
| 2030 | } else { | |
| 2031 |
1
1. verbosePrintInternal : removed call to java/io/PrintStream::println → KILLED |
out.println(); |
| 2032 | } | |
| 2033 | } | |
| 2034 | } | |
| 2035 | ||
| 2036 | lineage.removeLast(); | |
| 2037 | ||
| 2038 |
1
1. verbosePrintInternal : removed call to org/apache/commons/collections4/MapUtils::printIndent → KILLED |
printIndent(out, lineage.size()); |
| 2039 |
2
1. verbosePrintInternal : negated conditional → KILLED 2. verbosePrintInternal : removed call to java/io/PrintStream::println → KILLED |
out.println(debug ? "} " + map.getClass().getName() : "}"); |
| 2040 | } | |
| 2041 | ||
| 2042 | /** | |
| 2043 | * {@code MapUtils} should not normally be instantiated. | |
| 2044 | */ | |
| 2045 | private MapUtils() { | |
| 2046 | } | |
| 2047 | ||
| 2048 | } | |
Mutations | ||
| 109 |
1.1 |
|
| 128 |
1.1 2.2 |
|
| 129 |
1.1 |
|
| 130 |
1.1 |
|
| 132 |
1.1 2.2 |
|
| 148 |
1.1 2.2 |
|
| 149 |
1.1 2.2 |
|
| 170 |
1.1 |
|
| 182 |
1.1 2.2 |
|
| 196 |
1.1 |
|
| 210 |
1.1 |
|
| 227 |
1.1 |
|
| 229 |
1.1 |
|
| 230 |
1.1 |
|
| 231 |
1.1 2.2 |
|
| 233 |
1.1 |
|
| 234 |
1.1 2.2 |
|
| 236 |
1.1 |
|
| 238 |
1.1 2.2 3.3 |
|
| 242 |
1.1 2.2 |
|
| 257 |
1.1 2.2 |
|
| 274 |
1.1 2.2 |
|
| 294 |
1.1 2.2 |
|
| 315 |
1.1 2.2 |
|
| 338 |
1.1 2.2 |
|
| 354 |
1.1 |
|
| 357 |
1.1 |
|
| 358 |
1.1 |
|
| 360 |
1.1 |
|
| 375 |
1.1 |
|
| 391 |
1.1 |
|
| 406 |
1.1 |
|
| 422 |
1.1 |
|
| 442 |
1.1 |
|
| 458 |
1.1 |
|
| 459 |
1.1 |
|
| 461 |
1.1 |
|
| 462 |
1.1 |
|
| 464 |
1.1 |
|
| 479 |
1.1 |
|
| 496 |
1.1 |
|
| 511 |
1.1 |
|
| 527 |
1.1 |
|
| 547 |
1.1 |
|
| 563 |
1.1 |
|
| 564 |
1.1 |
|
| 566 |
1.1 |
|
| 567 |
1.1 |
|
| 569 |
1.1 |
|
| 584 |
1.1 |
|
| 601 |
1.1 |
|
| 616 |
1.1 |
|
| 632 |
1.1 |
|
| 652 |
1.1 |
|
| 668 |
1.1 |
|
| 669 |
1.1 |
|
| 671 |
1.1 |
|
| 672 |
1.1 |
|
| 674 |
1.1 |
|
| 691 |
1.1 |
|
| 706 |
1.1 |
|
| 721 |
1.1 |
|
| 741 |
1.1 |
|
| 757 |
1.1 |
|
| 773 |
1.1 |
|
| 774 |
1.1 |
|
| 776 |
1.1 |
|
| 777 |
1.1 |
|
| 779 |
1.1 |
|
| 795 |
1.1 |
|
| 810 |
1.1 |
|
| 825 |
1.1 |
|
| 845 |
1.1 |
|
| 861 |
1.1 |
|
| 876 |
1.1 |
|
| 878 |
1.1 2.2 |
|
| 879 |
1.1 |
|
| 899 |
1.1 |
|
| 914 |
1.1 |
|
| 931 |
1.1 |
|
| 933 |
1.1 |
|
| 934 |
1.1 |
|
| 935 |
1.1 |
|
| 937 |
1.1 |
|
| 940 |
1.1 |
|
| 964 |
1.1 |
|
| 979 |
1.1 |
|
| 993 |
1.1 |
|
| 994 |
1.1 |
|
| 1011 |
1.1 |
|
| 1013 |
1.1 |
|
| 1014 |
1.1 |
|
| 1017 |
1.1 |
|
| 1033 |
1.1 |
|
| 1034 |
1.1 |
|
| 1036 |
1.1 |
|
| 1037 |
1.1 |
|
| 1039 |
1.1 |
|
| 1056 |
1.1 |
|
| 1071 |
1.1 |
|
| 1086 |
1.1 |
|
| 1106 |
1.1 |
|
| 1122 |
1.1 |
|
| 1137 |
1.1 |
|
| 1139 |
1.1 |
|
| 1140 |
1.1 |
|
| 1143 |
1.1 |
|
| 1160 |
1.1 |
|
| 1175 |
1.1 |
|
| 1199 |
1.1 |
|
| 1213 |
1.1 2.2 3.3 |
|
| 1227 |
1.1 2.2 |
|
| 1242 |
1.1 2.2 |
|
| 1259 |
1.1 2.2 |
|
| 1297 |
1.1 |
|
| 1342 |
1.1 |
|
| 1376 |
1.1 |
|
| 1418 |
1.1 |
|
| 1434 |
1.1 |
|
| 1454 |
1.1 |
|
| 1475 |
1.1 |
|
| 1492 |
1.1 |
|
| 1510 |
1.1 |
|
| 1529 |
1.1 |
|
| 1547 |
1.1 |
|
| 1566 |
1.1 |
|
| 1588 |
1.1 |
|
| 1610 |
1.1 |
|
| 1619 |
1.1 2.2 3.3 |
|
| 1620 |
1.1 |
|
| 1677 |
1.1 2.2 |
|
| 1678 |
1.1 |
|
| 1681 |
1.1 |
|
| 1687 |
1.1 |
|
| 1693 |
1.1 |
|
| 1694 |
1.1 2.2 |
|
| 1696 |
1.1 2.2 3.3 |
|
| 1703 |
1.1 2.2 3.3 |
|
| 1705 |
1.1 2.2 |
|
| 1708 |
1.1 |
|
| 1732 |
1.1 |
|
| 1742 |
1.1 2.2 |
|
| 1773 |
1.1 |
|
| 1805 |
1.1 |
|
| 1819 |
1.1 |
|
| 1825 |
1.1 |
|
| 1845 |
1.1 |
|
| 1853 |
1.1 |
|
| 1882 |
1.1 |
|
| 1911 |
1.1 |
|
| 1927 |
1.1 |
|
| 1943 |
1.1 |
|
| 1966 |
1.1 |
|
| 1988 |
1.1 |
|
| 1990 |
1.1 |
|
| 1991 |
1.1 |
|
| 1992 |
1.1 |
|
| 1993 |
1.1 |
|
| 1995 |
1.1 |
|
| 1998 |
1.1 |
|
| 1999 |
1.1 |
|
| 2000 |
1.1 |
|
| 2003 |
1.1 |
|
| 2004 |
1.1 |
|
| 2006 |
1.1 |
|
| 2011 |
1.1 2.2 |
|
| 2012 |
1.1 2.2 |
|
| 2014 |
1.1 |
|
| 2015 |
1.1 |
|
| 2016 |
1.1 |
|
| 2019 |
1.1 |
|
| 2020 |
1.1 |
|
| 2021 |
1.1 2.2 |
|
| 2022 |
1.1 |
|
| 2024 |
1.1 2.2 3.3 4.4 |
|
| 2027 |
1.1 2.2 |
|
| 2028 |
1.1 |
|
| 2029 |
1.1 |
|
| 2031 |
1.1 |
|
| 2038 |
1.1 |
|
| 2039 |
1.1 2.2 |